How to generate 10.000 unique numbers?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to generate 10.000 unique numbers?
# 1  
Old 10-01-2010
How to generate 10.000 unique numbers?

hello,

does anybody can give me a hint on how to generate a lot of numbers which are not identically via scripting etc?
# 2  
Old 10-01-2010
Code:
echo {1..10000}

This User Gave Thanks to kurumi For This Post:
# 3  
Old 10-01-2010
Smilie

thanks but they should be more complex. with 12 to 18 chars. and more random.
# 4  
Old 10-01-2010
straight shell arithmetic handles numbers up to 4294967291. The shell random number generator gives values between 1 - 32767. This is a hack using bc - a calculator
Code:
cnt=0
while [[ $cnt -lt 10000 ]]
do
 echo "$RANDOM * $RANDOM * $RANDOM"
 cnt=$(( $cnt + 1 ))
 if [[ $cnt -gt 10000 ]] ; then  
    break
 fi
done | bc -l

Pretty much anything else will require some kind of non-shell appoach - perl, ruby, C....
This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 10-01-2010
bash code:
  1. #!/bin/bash
  2. while ((i<1000))
  3. do
  4.    N=$((RANDOM*1000000/32768))$((RANDOM*1000000/32768))
  5.    echo "${A[*]}" | grep $N && continue # if number already in the array
  6.    A&#91;$i]=$N
  7.    ((i++))
  8.    tput cup 0 0; echo "$i" # Monitoring purpose
  9. done
  10. # Display the array:
  11. for ((i=0; i<${#A[@]}; i++))
  12. do
  13.    echo ${A[$i]}
  14. done
This User Gave Thanks to frans For This Post:
# 6  
Old 10-01-2010
Code:
$ ruby -e 'BEGIN{ print ("100000".."999999").to_a.shuffle[0,2].join} '
645898445734

This User Gave Thanks to kurumi For This Post:
# 7  
Old 10-01-2010
Quote:
Originally Posted by jim mcnamara
straight shell arithmetic handles numbers up to 4294967291. The shell random number generator gives values between 1 - 32767. This is a hack using bc - a calculator
Code:
cnt=0
while [[ $cnt -lt 10000 ]]
do
 echo "$RANDOM * $RANDOM * $RANDOM"
 cnt=$(( $cnt + 1 ))
 if [[ $cnt -gt 10000 ]] ; then  
    break
 fi
done | bc -l

Pretty much anything else will require some kind of non-shell appoach - perl, ruby, C....
Thank you this worked, but it is not guaranteed that the numbers are unique right?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate 10000 unique audio file of 2MB each using shell script.

Hi, I want 10000+ unique Audio file of approx 2MB each. How can i generate numerous audio files using shell script. Any tool, command or suggestions are welcome. If i give one audio seed file then can we create numerous unique files with same seed file? Any help is highly appreciable.... (11 Replies)
Discussion started by: sushil.kumar
11 Replies

2. Shell Programming and Scripting

Script to generate sequence of numbers

I need awk script to generate part number sequencing based on data in multiple columns like below Input File --------- Col A|Col B|Col C| 1|a|x| 2|b|y| |c|z| | |m| | |n| And out put should be like 1ax 1ay 1az 1am 1an 1bx 1by (6 Replies)
Discussion started by: aramacha
6 Replies

3. Shell Programming and Scripting

Generate random numbers in script

i want to generate a random number through a script, and even if anyone reads the script, they wont be able to figure out what the random number is. only the person who setup the script would know it. something like this could work: random the full thread is here: ... (13 Replies)
Discussion started by: SkySmart
13 Replies

4. Shell Programming and Scripting

Generate unique mac address

Hi, I want to generate 2000 mac address. Please let me know how to do so. Perl script or there is some tool availlable wherein i can give the count and it will generate that many mac-address Thanks, Kriti (4 Replies)
Discussion started by: kriti
4 Replies

5. Programming

generate array of random numbers

hi guys, I am writing a c program that generates a two dimensional array to make matrix and a vector of random numbers and perform multiplication. I can't figure out whats wrong with my code. It generates a matrix of random numbers but all the numbers in the vector array is same and so is the... (2 Replies)
Discussion started by: saboture88
2 Replies

6. Shell Programming and Scripting

Generate unique user id with each addition of data

As I add new data to database.txt I want to generate a unqiue User Id. This is my current solution. echo $RANDOM:$lname:$fname >> database.txt But I seem to have problems when I try and use $RANDOM for formatting like so: grep "^4539" database.txt | awk -F":" '{print "User... (4 Replies)
Discussion started by: yonkers062986
4 Replies

7. Shell Programming and Scripting

Generate numbers 000 to 999

I have tried to make this script to generate: 000 001 002 ... 997 998 999 i=0 while do if then echo "00"$i else if && then echo "0"$i (5 Replies)
Discussion started by: locoroco
5 Replies

8. Shell Programming and Scripting

How to generate a series of numbers

Hi All, I have a requirement where in I have an input as follows:- input=1-4,6,8-10,12-15 I need to explode this range into an output file as follows:- 1 2 3 4 6 8 9 10 12 13 14 15 My input may vary like 1,5-9,11-13,15-17....... (3 Replies)
Discussion started by: rony_daniel
3 Replies

9. Shell Programming and Scripting

generate level numbers

Hi... I have a sequence of jobs and its predecessors.. Input Job_Name Predecessor A NULL B1 A B2 A B3 B1 C B3 C B2 So based on these i have to generate the level Number What i mean is Let A be level 1 for B1 to happen it should have done A so B1 level is A+1 = 1+1 = 2 (12 Replies)
Discussion started by: pbsrinivas
12 Replies

10. Shell Programming and Scripting

need to generate unique id from constant sid

Hello I have multiple accounts that running application that uses unique port number I want to generate this port from some sid number that stays constant for every user account , is there any place in the system that generate number that is unique to the account ? thanks (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question