Searching \ for 'Random number generation' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/method/math.htm?key=random
Search entire site for: 'Random number generation'.

Truncated match.
PICList Thread
'Random number generation'
1999\01\31@212159 by David Sprenkle

picon face
I need some code or a algorithm for generating a 8 bit random number on
a PIC.  Does anyone have any code or an algorithm to accomplish this?

P.S.  I need working code or a working algorithm, not theory.  Thanks.
I been off the list for a while so I apologize if I am reposting
anything.

--
David Sprenkle

1999\01\31@214036 by Graeme Smith

flavicon
face
In "PIC your personal introductory course" John Morton suggests
simply adding h'27' repetitively. I think that the result won't be quite
random, but it does cycle through a long cycle without repeats.

Most Pseudo Random numbers require multiplication (or iterative addition)
to accomplish. The main requirement is to find a "magic number" that not
only maximizes runtimes without repeats but also avoids easy analysis as a
"SERIES" so that it is easier to avoid prediction. This might be harder on
a "LOW END PIC" than some of the other options. One way of further
confusing the issue, is to use a "RANDOM SEED" such as a random number
created by a different pseudo random number generator, to generate the
base that you multiply/add to etc, every so often.

                               GREY


GRAEME SMITH                         email: spam_OUTgrysmithTakeThisOuTspamfreenet.edmonton.ab.ca
YMCA Edmonton

Address has changed with little warning!
(I moved across the hall! :) )

Email will remain constant... at least for now.


On Sun, 31 Jan 1999, David Sprenkle wrote:

{Quote hidden}

1999\01\31@215114 by dave vanhorn

flavicon
face
At 06:11 PM 1/31/99 -0800, David Sprenkle wrote:
>I need some code or a algorithm for generating a 8 bit random number on
>a PIC.  Does anyone have any code or an algorithm to accomplish this?
>
>P.S.  I need working code or a working algorithm, not theory.  Thanks.
>I been off the list for a while so I apologize if I am reposting
>anything.
>
>--
>David Sprenkle


I have code for the AVR8515 which you could easily translate, for a maximal
length pseudorandom number generator.
You won't find cryptographically random cheap.
You won't find provably unpredictable cheap.

The PN generator can give you anything up to it's length -1 with all
possible values equally distributed, but of you use the full length, then
the all zeroes state can't occur. (the generator would lock up if you
initted it to that value)

You can pick and choose your bits, invert them, so the output is not easily
recognizable as a fixed pattern.

It really depends on what you want to use it for..

1999\01\31@215539 by Sean Breheny

face picon face
Which algorythm you choose also depends upon what the resulting number will
be used for. If it is for noise generation, it probably doesn't need to be
all that random. If it is for a random delay in a communications system,
likewise, I don't think it would need to be really very random, just enough
that the system won't get locked into a cetain repetitive state. However,
if it is for security or for picking lottery numbers,bingo, etc, it better
be pretty random.

Sean

At 07:39 PM 1/31/99 -0700, you wrote:
{Quote hidden}

+---------------*----------------+
| Sean Breheny                   |
| Amateur Radio Callsign: KA3YXM |
| Electrical Engineering Student |
+---------------*----------------+
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
shb7spamKILLspamcornell.edu  Phone(USA): (607) 253-0315 ICQ #: 3329174


'Random number generation'
1999\02\01@144136 by w. v. ooijen / f. hanneman
picon face
> I need some code or a algorithm for generating a 8 bit random number on
> a PIC.  Does anyone have any code or an algorithm to accomplish this?

Random (actually pseudo-random!) numbers are useually generated by
a shift register with XOR feedback. You can vary the length of the
SR to get a suitable cyclus length.

The jal compiler has a such a reandom library which is so small that
I've attched it below. You should be able to translate this into assembler
(in fact is it almost assembler). I deleted the copyright notice, but it
is covered by the GNU LGPL so unless you want to sell a library based
upon it you can use it freely. When you are too lazy to translate
the code below into assembler you could download the jal compiler
and let it do the job. (http://www.xs4all.nl/~wf/wouter/pic/jal)

regards,
Wouter.

var byte _random_b1
var byte _random_b2
var byte _random_b3

-- make sure there is at least one bit set!
asm bsf _random_b1, 0

procedure _random_shift is
  -- from the art of electronics, p657:
  -- 24 bits LFSR needs xor feedback from taps at 17, 22 and 23
  assembler
     movlw 0
     btfsc _random_b3, 1
       xorlw 0xFF
     btfsc _random_b3, 6
       xorlw 0xFF
     btfsc _random_b3, 7
       xorlw 0xFF
     addlw 1
     rlf _random_b1, f
     rlf _random_b2, f
     rlf _random_b3, f
  end assembler
end procedure

var bit  _random_bit   at _random_b1 : 0
var byte _random_byte  at _random_b1

procedure randomize( byte in n = 0 ) is
  _random_b1 = n
  _random_b2 = 1
  _random_b3 = 0
  for 24 loop
     _random_shift
  end loop
end procedure

function random_bit return bit is
  _random_shift
  return _random_bit
end function

function random_byte return byte is
  for 8 loop
     _random_shift
  end loop
  return _random_byte
end function

1999\02\01@152307 by Roland Andrag

flavicon
face
If you are considering a Pic17Cxx have a look at AN544 in the embedded
control handbook.
Even if you are using a 16C the algorithm should be easily implemented - it
basically involves boolean operations and shifting on 16 bits.

Cheers
 Roland


{Quote hidden}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...