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?

echo {1..10000} 
1 Like

:slight_smile:

thanks but they should be more complex. with 12 to 18 chars. and more random.

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

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....

1 Like


#!/bin/bash
while ((i<1000))
do
N=$((RANDOM*1000000/32768))$((RANDOM1000000/32768))
echo "${A[
]}" | grep $N && continue # if number already in the array
A[$i]=$N
((i++))
tput cup 0 0; echo "$i" # Monitoring purpose
done
# Display the array:
for ((i=0; i<${#A[@]}; i++))
do
echo ${A[$i]}
done

1 Like
$ ruby -e 'BEGIN{ print ("100000".."999999").to_a.shuffle[0,2].join} '
645898445734
1 Like

Thank you this worked, but it is not guaranteed that the numbers are unique right?

Here's a short Perl script that generates 10 distinct random numbers between NUM1 = 999,999,999,999 (12 digits) and NUM2=999,999,999,999,999,999 (18 digits). $range in the script is NUM2 - NUM1.

$
$ perl -e 'BEGIN {$min=999_999_999_999; $range=999_999_000_000_000_000; $n=0; $total=10}
           do { $x=sprintf("%18.0f\n",int(rand($range))+$min);
                if (not defined $rnd{$x}) {$rnd{$x}++; print $x; ++$n}
              } until ($n == $total)'
435059158691406270
823944267852783230
160920028533935550
857452535125732480
490753683074951170
386475222900390660
919342121673584000
339935962799072260
483002225982665980
952148485351562500
$
$ perl -e 'BEGIN {$min=999_999_999_999; $range=999_999_000_000_000_000; $n=0; $total=10}
           do { $x=sprintf("%18.0f\n",int(rand($range))+$min);
                if (not defined $rnd{$x}) {$rnd{$x}++; print $x; ++$n}
              } until ($n == $total)'
775116191680908160
462250293609619140
214142631561279300
963470495513916030
866027966003417980
710083297729492220
 12421641876220704
632690796997070340
597626134796142590
502472421356201150
$
$ perl -e 'BEGIN {$min=999_999_999_999; $range=999_999_000_000_000_000; $n=0; $total=10}
           do { $x=sprintf("%18.0f\n",int(rand($range))+$min);
                if (not defined $rnd{$x}) {$rnd{$x}++; print $x; ++$n}
              } until ($n == $total)'
868713510192871040
987182630004882820
978912374603271420
379791879974365250
296448457458496060
946075493377685500
 26398678680419920
513519773590087870
920135577911376900
439606273284912130
$

tyler_durden

1 Like