Re: 8 Bit Random Numbers
- From: Nobody <nobody@xxxxxxxxxxx>
- Date: Fri, 06 Feb 2009 04:40:32 +0000
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.
.
- Follow-Ups:
- Re: 8 Bit Random Numbers
- From: nospam
- Re: 8 Bit Random Numbers
- From: Jasen Betts
- Re: 8 Bit Random Numbers
- Prev by Date: Re: 8 Bit Random Numbers
- Next by Date: Re: Transformer Current
- Previous by thread: Re: 8 Bit Random Numbers
- Next by thread: Re: 8 Bit Random Numbers
- Index(es):
Relevant Pages
|
Loading