I thought I would post how to generate a random number using Bash because it took me a while to find the information.
Now you can use $NUMBER anywhere in your script and you should have a random number.Code:NUMBER=`echo $RANDOM%900 | bc`
If I'm not wrong RANDOM is a shell variable. I think you use it directily:
OrCode:NUMBER=$RANDOM
Code:number=$((RANDOM % somenumber))
Last edited by asafe; 08-03-2010 at 11:35 AM.
I think the better way is to use /dev/urandom for this. Read random bits from the file. You can obtain large range. $RANDOM has only 0-32767. E.g.See http://94.228.168.188/en/articles/article_03.html for details.Code:cat /dev/urandom|od -N4 -An -i
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks