Re: [Nolug] Random numbers in bash

From: Joey Kelly <>
Date: Thu, 14 Aug 2003 17:28:35 +0000
Message-Id: <>

Thou spake:
>>-----Original Message-----
>From: Ron Johnson []
>>Sent: Thursday, August 14, 2003 2:50 PM
>>Subject: [Nolug] Random numbers in bash
>>Anyone know if that's possible? For example, I'd like to generate
>>a random number between 1 and 100.
>$RANDOM returns a number between 0 and 32767

I wrote a dice-rolling program on my HP 41C calculator in college sometime
during the last millenium. Basically, here's what I did:

Take the range of possible values and multiply by some factor that will give
you results in the range you are looking for. You might have to take this
number and add 1 to it (else you'll be getting a zero, which is outside your
stated range). Then round the real value and cast it to get an integer
(different languages cast differently, you'll have to research this).

Hope this helps :-)

Joey Kelly
< Minister of the Gospel | Computer Networking Consultant >
"Democracy is two wolves and a lamb voting on what to have for lunch.
Liberty is a well-armed lamb contesting the vote."
Nolug mailing list
Received on 08/14/03

This archive was generated by hypermail 2.2.0 : 12/19/08 EST