Positron Compiler Documentation

Random

Positron16 · Revision 1.1.3.5 · PDF page 350

Assignment Variable = Random

Generate a pseudo-randomised value.

None. Assignment Variable is a user defined variable that will hold the pseudo-random value. The pseudo-random algorithm used has a working length of 1 to 65535.

Device = 24HJ128GP502        ' Select the device to compile for
Declare Xtal = 16

Dim wRandomValue as Word

wRandomValue = Random        ' Get a pseudo random number into wRandomValue
Random wRandomValue           ' Get a pseudo random number into wRandomValue

All microcontrollers use a pseudo random number generator because they do not have a random noise generator peripheral, so the parameter that is used for Seed will always produce the same sequence of random values from the Random command.

It is important to be aware of this because each microcontroller will produce the same pseudo random values. If true random number generation is required, find a source of random noise that can be fed into the microcontroller’s ADC and use this value to place in the Seed command.

See also: Seed.

View original PDF page 350Open page in PDFOriginal PDF page 350