Pseudorandom number generation on a PIC
Robert A. LaBudde email (remove spam text)
<x-flowed>If all that is wanted is a small run length of pseudorandom numbers, this
can be accomplished by the following 8-bit multiplicative-additive
X(n+1) = [27 X(n) + 3] mod 256
= [16 X(n) + 8 X(n) + 2 X(n) + X(n) + 3] mod 256
= [32 X(n) - 4 X(n) - X(n) + 3] mod 256
with X(0) = 27.
The output of this sequence should appear as reasonably 'white' noise.
Note that 16 X(n) is X(n) shifted left 4 bits with zero fill, etc., and mod
256 is simply accomplished by disregarding overflow bits and keeping only
the low order 8 bits of the addend.
I would presume that a linear shift register algorithm would give superior
run length and spectral properties for the same computation time. I'll try
to dredge up a validated one and post it to the list.
Robert A. LaBudde, PhD, PAS, Dpl. ACAFS e-mail: lcfltd.comral
Least Cost Formulations, Ltd. URL: http://lcfltd.com/
824 Timberlake Drive Tel: 757-467-0954
Virginia Beach, VA 23464-3239 Fax: 757-467-2947
"Vere scire est per causas scire"
In reply to: <Pine.LNX.email@example.com>
See also: www.piclist.com/techref/microchip/math/index.htm?key=random
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the