Re: 8 Bit Random Numbers



On Thu, 05 Feb 2009 11:03:52 -0600, George wrote:

So if randomness (rather than just non-repeating) is
important to whatever you're doing, one solution might be to
run a much larger shift register - 30 bits or more - and do
8 iterations to produce the next "random" byte for your use.
All 8 bits will have been replaced by new ones with no
obvious relationship to each other or to what was there
before.

Of course the 30-bit register is still deterministic, but
the non-repeating sequence is still quite lengthy: 2^30 - 1.

You would have to shift four bytes instead of one, and do
that and the XORs eight times instead of one, but, you know,
processors are pretty fast now.

If you want highly-random bytes, and can spare 258 bytes of RAM, I would
echo nospam's suggestion to use RC4 (aka ArcFour, as RC4 is a trademark):

byte x, y
byte a[256] ; a[] is a permuation, i.e. each of the values 0-255
; occurrs exactly once.

proc next_byte()
byte t

x = x + 1
y = y + a[x]
swap(a[x], a[y])
t = a[x] + a[y]
return a[t]
end

A word of caution: do not use the XOR trick for the swap(); it fails
if x == y.

.



Relevant Pages

  • Re: 8 Bit Random Numbers
    ... run a much larger shift register - 30 bits or more - and do ... iterations to produce the next "random" byte for your use. ... echo nospam's suggestion to use RC4 ... do not use the XOR trick for the swap; ...
    (sci.electronics.basics)
  • Re: How can I build a table with the time values of a timer from a while loop
    ... But I was wondering why you use the shift register? ... I use a shift register to store the 2D array elements from previous iterations, so that I can include the values of present iteration at the end of the array and update the Table display ... This will happen if you do not clear/empty the table or do not initialise a shift register (by onnecting an empty array at the initialization of shift register) before each Run ...
    (comp.lang.labview)

Loading