# RND() RANDOMIZE

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
RND( [ number ] )
RANDOMIZE nbr

Description:
Returns a pseudo-random number in the range of 0 to 0.999999.

The 'number' value is ignored if supplied. The Colour Maximite 2 uses the hardware random number generator in the STM32 series of chips to deliver true random numbers.

This means that the RANDOMIZE command is no longer needed and is not supported.

RANDOMIZE nbr
Seed the random number generator with ‘nbr’.
On power up the random number generator is seeded with zero and will generate the same sequence of random numbers each time.
To generate a different random sequence each time you must use a different value for ‘nbr’. One good way to do this is use the TIMER function.
For example

RANDOMIZE TIMER
' or use an analog pin as a reference
spare = 23 ' any spare analog pin left floating.
SETPIN spare, AIN
RANDOMIZE PIN(spare)*1000
PRINT RND()

If your device doesn't support RANDOMIZE and you require a repeatable pseudo random number sequence, use the following
Any time you seed the pseudo() function with the same number, you will get a repeatable sequence

print pseudo(1245) ' seed the random number generator
for n = 1 to 10
print pseudo()
next n
function pseudo(s as integer) as float
static integer x=7
static integer a=1103515245
static integer c=12345
static integer m=2^31
if s <> 0 then x = s
x=(a * x + c) mod m
pseudo = x/m
end function

Last edited: 29 September, 2020