Pseudo Random Number Generator
These routines generate a sequence of pseudo-random numbers using the
ordinary linear feedback shift register technique. Both routines
require memory to hold the last number generated. They produce a
predictable but randomly distributed sequence of numbers, similar to
the rand() function in most C libraries.
No routine analogous to
srand() is provided, but it is easily implemented by writing the
seed value into the memory which holds the previously generated
number. These routines check for zero (the illegal value), so it is not
necessary to initialize the memory with a seed value unless a
predictable starting seed is required or a truely random number is
available.
- RAND8
- Generate an 8 bit pseudo random number, from 1 to 255. The number is
returned in Acc.
- RAND16
- Generate a 16 bit pseudo random number, from 1 to 65535. The number is
returned in Acc (lsb) and B (msb).
This code is available as plain text or in a
zip file.
Paul's 8051 Code Library, Paul Stoffregen
http://www.pjrc.com/tech/8051/rand.html
Last updated: November 28, 2003
Status: complete
Suggestions, comments, criticisms:
<paul@pjrc.com>