Friday, March 30, 2007

random number generator

i just happen to know that we can easily generate random number using $RANDOM
$ echo $RANDOM
12517
$ echo $RANDOM
18362
$ echo $RANDOM
26219
$ echo $RANDOM
26056
$ echo $RANDOM
30305
$ echo $RANDOM
9606
but if you want to get smaller random number eg. less than 100, you can do this:
$ number=$((RANDOM%100))
$ echo $number
75
20 random numbers less than 100:
$ count=1
$ while [ $count -le 20 ] ; do number=$((RANDOM%100)); echo $number; let "count += 1"; done
93
14
19
96
61
86
63
48
45
26
11
0
89
54
11
84
17
10
99
12
random number less than 10:
$ number=$((RANDOM%10))
$ echo $number
4
5 random numbers less than 10:
$ count=1
$ while [ $count -le 5 ] ; do number=$((RANDOM%10)); echo $number; let "count += 1"; done
3
4
9
6
7
and so on...

4 comments:

tentangseseorang said...

saya code php tahu, tapi bab linux command line, then solaris command line memang hancus...ajar boleh ehehehe

singautara said...

saya bleh ajaq, hang nih laki ka pompuan, kalo jantan maleh aaaa...
ekkekkekekekek

Red Mummy said...

ttg seseorang is one of the active reader blog akuuuuu aaaaa

budak baik aaa dia...of cos la laki, ko lion manjang nak kan awek ye, report kat bini ko kang

singautara said...

kekekekekeek.....lawak ja la.
kak red, pi masuk blog bini waaa :)