Generating a random number (GRX)
Kenneth Brody
kenbrody at spamcop.net
Wed May 12 09:37:30 PDT 2010
On 5/12/2010 12:14 PM, Chris Sellitto wrote:
> filePro® version 5.0.14RN9
> Windows Server/XP environments.
>
> I am trying to generate a number between 1-20, and seem to be doing something wrong. I keep generating the same number over and over. Below is a small test I tried, and RN always displays as 2192.
[...]
> ◄ If: rn eq ""
> Then: rn(4,.0)=rand("20")
> 225 ------- - - - - - - - - - - -
> ◄ If:
> Then: rn=rand(" ")
[...]
Re-read the documentation on RAND(). The code as-written will re-seed the
PRNG with "20" every time, thereby giving you the same "random" number every
time.
Also, RAND() returns a number from 0 to 32767 (inclusive). To get a number
from 1-20, you need to do something with the return value to get it into the
range you want. A simple MOD() of 20 and add 1 will get you close, though
it will slightly favor 1-8 over 9-20.
--
Kenneth Brody
More information about the Filepro-list
mailing list