Seed
Syntax
Seed Value
Overview
Seed the pseudo random number generator, in order to obtain a more random result.
Parameters
Value can be a variable, constant or expression, with a value from 1 to 65535. A value of $0345 is a good starting point.
Example
' Create and display a Random number
Device = 24FJ64GA002 ' Select the device to compile for
Declare Xtal = 32
Declare Hserial_Baud = 9600 ' UART1 Baud rate
Declare Hrsout1_Pin = PORTB.14 ' Select the pin for TX with USART1
Dim MyWord as Word
RPOR7 = 3 ' Make Pin RP14 U1TX
Seed $0345 ' Seed the pseudo random generator with $0345
Do
MyWord = Random
HRsoutLn Dec MyWord
DelayMs 500
Loop
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.
See also: Random.
