Random
Syntax
Assignment Variable = Random
Overview
Generate a pseudo-randomised value.
Parameters
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 (only zero is not produced).
Example
Device = 18F26K40
' Compiler for an 18F device
Declare Xtal = 20
' Tell the compiler the device is operating at 20MHz
Declare Hserial_Baud = 9600 ' Choose the Baud rate for HRsoutLn
Dim MyWord as Word
Seed $0345
' Seed the pseudo random number generator
MyWord = Random
' Get a pseudo random number into MyWord
HRsoutLn Dec MyWord
Note
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.