[Solved] Help with random pick 1000 number from range 1 to 150000

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Help with random pick 1000 number from range 1 to 150000
# 1  
Old 03-04-2014
[Solved] Help with random pick 1000 number from range 1 to 150000


Do anybody knows how to use awk or any command to random print out 1000 number which start from range 1 to 150000?

I know that "rand" in awk can do similar random selection.
But I have no idea how to write a code that can random pick 1000 number from range 1 to 150000 Smilie

Thanks for any advice.
# 2  
Old 03-04-2014
Try this in awk:

awk "BEGIN{srand($RANDOM); for(i=0;i<1000;i++)print int(1+ rand()*150000)}"

These 2 Users Gave Thanks to Chubler_XL For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generating Random Number in certain range

Hi there I am trying to generate a random number between 40 and 70 using the shell here is my code so far and it keeps going above 70. all help much appreciated! comp=$(( RANDOM%70+40 )) echo $comp (4 Replies)
Discussion started by: faintingquiche
4 Replies

2. Programming

random number

How can I choose randomly the row numbers of my file in awk? (4 Replies)
Discussion started by: Homa
4 Replies

3. Shell Programming and Scripting

Unix random number generate in given range

Hi All, I have extracted some report from database for few activities done. Now I have a requirement to add some random time(In range of 10-35) in front of each activity. Can be generated random numbers in any bash/sh shell within a given number range, let's say in between 10-30. ... (10 Replies)
Discussion started by: gr8_usk
10 Replies

4. Shell Programming and Scripting

Pick random file from ls command.

Lets say I want to pick a random file when I do an "ls" command. I don't have set number of files in each directory. ls | head -1 This gives me the first one in each directory, is there a way to do the same but pick a random one. (3 Replies)
Discussion started by: elbombillo
3 Replies

5. What is on Your Mind?

Pick a Number Between 0 and 20 for 1 Million Bits

Here is an easy game! I wrote a number between 0 and 20 (that can include 0 and 20) on a piece of paper. I am staring at it now, imagining the number so you can read my mind ;) Reply once, and only once, with a number from 0 to 20 and the first person to guess it wins 1,000,000 Bits. ... (24 Replies)
Discussion started by: Neo
24 Replies

6. Programming

C Help; generating a random number.

Im new to C, and Im having a hard time getting a random number. In bash, I would do something similar to the following to get a random number; #!/bin/bash seed1=$RANDOM seed2=$RANDOM seed3=$RANDOM SEED=`expr $seed1 * $seed2 / $seed3` echo ${SEED%.*} Now, in online examples... (4 Replies)
Discussion started by: trey85stang
4 Replies

7. Shell Programming and Scripting

How to Pick Random records from a large file

Hi, I have a huge file say with 2000000 records. The file has 42 fields. I would like to pick randomly 1000 records from this huge file. Can anyone help me how to do this? (1 Reply)
Discussion started by: ajithshankar@ho
1 Replies

8. Shell Programming and Scripting

Generating random number within a specific range (0.5-1.5)

Hello, need a way to generate numbers within 0.5-1.5 range Has to be totally random: 0.6 1.1 0.8 1.5 0.6 and so on.... How to? (10 Replies)
Discussion started by: TehOne
10 Replies

9. Shell Programming and Scripting

Random numbers from 0 to 1000

Hello All, I want to make a simple script which generate random number from 0 to 1000. and simply display it. Plz HELP!!!!!! Regards, Waqas Ahmed (2 Replies)
Discussion started by: wakhan
2 Replies

10. UNIX for Dummies Questions & Answers

Displays line number 1000 to 2000

Hi, I have 1 million records and want to extract lines betwen 10000 -20000 and put it in another file. Could you please suggest a command for this. Thanks in advance (3 Replies)
Discussion started by: unxusr123
3 Replies
Login or Register to Ask a Question