The Random function returns a random non-negative whole number within a finite range.
result = Random( [ minOrMax ] [, [ max ] ] [, seed ] ] ) |
When a seed is not specified for the first use of the random function, then an arbitrary seed value will be automatically used. This arbitrary value is usually obtained from the system's internal clock.
Portability note: different implementations can use a different internal random number generator. The sequence of numbers based on a random number seed may differ among these implementations.
Examples:
say Random() -- shows a number between 0 and 999, with an arbitrary seed say Random( 1 ) -- shows a number between 0 and 1, a coin flip with an arbitrary seed say Random( 1, 6 ) -- shows a number between 1 and 6, with an arbitrary seed say Random( 1, 6, 2002 ) -- shows a number between 1 and 6, with a specific seed
/* the following generates 6 random lottery numbers */ limit = 49 picks = '' /* selected picks */ /* prepare 6 random numbers */ do until words( picks ) = 6 /* need 6 picks */ pick = random( 1, limit ) /* get another random number */ if wordpos( pick, picks ) = 0 then /* not already picked? */ picks = picks pick /* remember pick */ end /* end loop */ /* format results */ say center( "Here come 6 picks [range: 1-"limit"]", 79 ) /* title line */ say center( strip( picks ), 79 ) /* show 6 picks */ say center( "Good luck", 79 ) /* closing remark */ |