05-07-2003, 12:11 PM
you failed to specify the range. I've got an easy scheme to do what you ask...however, I need to know what range of numbers you are looking for!!! If you need a 10 bit number, there's no sense working with 8-bits, eh??!!!
Quote:Plasma357, your scheme does indeed produce a pattern. Plotting the output of your code indicates the problem:
'random number generator--Joe Campbell
'This pattern will repeat...it's 640-bit, so there are only
'4.6x10^192 possible states!!! This pattern will only visit some
'fraction of the possible states...perhaps 25% Still...you want a
'random sequence of 2-byte integers??? choose any screen position of the
'developed field and take 16-bits...move down a line then take another 16.
'the numbers represented will pass every test of randomness. The center
'column of this unbounded automata is used by Mathmatica for generate random
'numbers. See Stephen Wolfram's "A New Kind of Science". I have implemented
'a strong secret key encryption using this so-called "rule 30" automata.
SCREEN 11
CLS
DIM a(1 TO 640) AS INTEGER
DIM b(1 TO 640) AS INTEGER
a(320) = 1 'starting condition...simplist case...a single bit in a field of zeros
'output is "just as random" as a for a more complex seed.
'RANDOMIZE TIMER: FOR t = 1 TO 640: a(t) = RND: NEXT t 'this is the "maximally random" starting condition
DO
FOR y = 1 TO 480
b(1) = (a(640) XOR (a(1) OR a(2))) 'special case wrapping
FOR x = 2 TO 639
b(x) = (a(x - 1) XOR (a(x) OR a(x + 1))) 'normal case
NEXT x
b(640) = (a(639) XOR (a(640) OR a(1))) 'special case wrapping
FOR x = 1 TO 640
PSET (x, y), b(x)
SWAP a(x), b(x)
NEXT x
NEXT y
LOOP
Quote:Nope, nope.
Your random number generator has a pattern that is created from the code.
The code *is* the pattern.
DECLARE SUB seed (a%(), randomnum#, b%(), maxwidth%)
DECLARE SUB stepautomata (a%(), randomnum#, b%(), maxwidth%)
DECLARE SUB rando (a%(), randomnum#, b%(), maxwidth%)
DEFINT A-Z
SCREEN 0
maxwidth% = 1000 'Set maxwidth% as big as you want, but at least as big
'as the bit-depth of the random number...in this case 32 is absolute minimum.
'if you make it small, the automata will repete and non-random output will
'be observed.
DIM a(0 TO maxwidth%) AS INTEGER 'arrays that hold automata
DIM b(0 TO maxwidth%) AS INTEGER 'a() is last complete line, b() is next line
CALL seed(a%(), randomnum#, b%(), maxwidth%)
'after this line, random numbers are available with CALL rando
'for example, the following loop fills screen with random dots.
SCREEN 11
DO
CALL rando(a%(), randomnum#, b%(), maxwidth%) 'get a random number...
x = 640 * randomnum# 'and scale it for your purposes
CALL rando(a%(), randomnum#, b%(), maxwidth%) 'get another...
y = 480 * randomnum#
PSET (x, y)
LOOP UNTIL INKEY$ <> ""
END
SUB rando (a%(), randomnum#, b%(), maxwidth%) STATIC
IF position + 32 > maxwidth% THEN 'checks to see if a new line is needed
CALL stepautomata(a%(), randomnum#, b%(), maxwidth%) 'update the array a%()
position = 0
END IF
grabaword# = 0 'reset value between calls
FOR x = 0 TO 31 'bit-depth of random number
grabaword# = grabaword# + (a%(position) * (2 ^ x)) 'grab a 32 bit chunk of a%() and convert to a double precision number
position = position + 1 'keep track of where you are on in array
NEXT x
'note...x=32 here
randomnum# = grabaword# / ((2 ^ x) - 1) 'normalize so that randomnum#
'will be in the range 0 to 1
END SUB 'just like the basic function RND
SUB seed (a%(), randomnum#, b%(), maxwidth%) STATIC
PRINT "seeding"
'this is needed to get array filled with indeterminate data.
a%(0) = 1 'starting condition...simplest case...a single "1" in a
'field of zeros. The output is "just as random" as with
'a more complex seed. Try the next line to see this.
'this is the "maximally random" starting condition:
'RANDOMIZE TIMER: FOR t = 0 TO maxsize%: a(t) = RND: NEXT t
FOR t = 0 TO maxwidth% \ 2 '2 is used b/c automata expands in both directions
CALL stepautomata(a%(), randomnum#, b%(), maxwidth%)
NEXT t
CLS
END SUB
SUB stepautomata (a%(), randomnum#, b%(), maxwidth%) STATIC
'this steps the automata forward...and is the source of the randomness
b%(0) = (a%(maxwidth%) XOR (a%(0) OR a%(1))) 'special case wrapping left
FOR x = 1 TO maxwidth% - 1
b%(x) = (a%(x - 1) XOR (a%(x) OR a%(x + 1))) 'normal case
NEXT x
b%(maxwidth%) = (a%(maxwidth% - 1) XOR (a%(maxwidth%) OR a%(0))) 'special case wrapping right
FOR x = 0 TO maxwidth% 'puts new values in a%()
SWAP a%(x), b%(x)
NEXT x
END SUB
Quote:Oh.....hm... ok.
I might find a correlation..............................................