Here's my analysis as yet of the RNG table. I'd love to do more, but I'm just not feeling it right now.
The RNG table boils down to just 48 different numbers and three parameters. It may be fewer than that, but I simply can't find a pattern among them. Here's our new table, from which we can construct the entire RNG table:
column | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15
-------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
number | 3| 6| 7|13|11| 1|15|10|12| 9| 8| 2| 4|14| 0| 5
-------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
row |10|11| 1|12| 5| 9| 6| 3|15|11| 2| 7| 2| 0|15|15
-------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
stagger| 5|15|13| 9| 5| 1|13|11| 1| 3| 3| 7|11|15| 3| 9
Obviously, some explanation is warranted. The
column simply indicates a column of the RNG table. The
number is the RNG number output somewhere in that column. Take a moment to verify that 3 appears in column 0, 6 appears in column 1, 7 appears in column 2, and so on. Note that every number from 0 through 15 appears in a unique column.
The
row is the row in which that number appears. So
row and
column taken together signify the locations of the numbers 0 through 15. For example, number 8 appears in row 2, column 10, and we'll therefore find it at RNG index 2A. You'll notice that the
row values are not all unique, so I question whether there's a deeper pattern to be found. If they were unique, I'd still be searching and not typing this up.
The
stagger value indicates something a little hard to explain. Take
row, add
stagger to it (mod 16), and in this new spot, put
number plus 32. Do this seven times (eight if you include placement of the original
number). If you've done this carefully for all 16 columns, you will have placed half the numbers from 0 to 255; you'll have 0 through 15, 32 through 47, 64 through 79, and so on.
Stagger is always coprime with 16 (i.e., always odd) because if it were divisible by 2, the pattern described above would cause it to "crash into itself".
To place the remaining numbers, for a given
column, find
row plus eight (again, mod 16). This is 128 indices away. In this spot, put 255 minus
number. Now add
offset to this row and
subtract 32 from the previous number. Do this a total of seven times (again, eight if you include placement of the original number). If you do this for every column, you will construct the complete RNG table.
If that was confusing, let me walk you through a quick example. We'll fill in the first column (column 0):
- - - - - - -
0 60
- - - - - - -
1 156
- - - - - - -
2 252 252 252
- - - - - - -
3 163 163 163 163
- - - - - - -
4 67 67 67 67
- - - - - - -
5 28
- - - - - - -
6 124
- - - - - - -
7 220 220
- ---> - ---> - ---> - ---> - ---> - ---> -
8 195 195 195 195
- - - - - - -
9 99 99 99 99
- - - - - - -
10 3 3 3 3 3 3
- - - - - - -
11 92
- - - - - - -
12 188
- - - - - - -
13 227 227 227 227
- - - - - - -
14 131 131 131 131
- - - - - - -
15 35 35 35 35 35
- - - - - - -
blank column | 3 belongs | stagger is 5, | continue until | put 252 8 rows | put 220 five | continue until
in column 0, so go down five eight numbers away from 3 rows below the column is
row 10 rows and put are placed filled
35 there
Well, I'm disappointed I can't break it down any further than that. If you notice any other patterns, I'd love to hear them. I have a gut feeling that there are deeper patterns because it seems like an instance where they'd cut back on memory usage-- it's already semi-automated, why not fully? Still, I can't find any pattern to
row or
stagger, so they may just be spelled out somewhere in the code.
Edit: Just noticed something new. Each
number is 8 columns away from its complement. That's nifty, but it doesn't simplify things much.
Edit 2: Here's an RNG table generator in Lua script form:
n={[0]=3,6,7,13,11,1,15,10,12,9,8,2,4,14,0,5}
r={[0]=10,11,1,12,5,9,6,3,15,11,2,7,2,0,15,15}
s={[0]=5,15,13,9,5,1,13,11,1,3,3,7,11,15,3,9}
RNGTable={}
for c=0,15 do
for i=0,7 do
currrow=(r[c]+i*s[c])%16
currnum=n[c]+32*i
RNGTable[16*currrow+c]=currnum
end
for j=0,7 do
currrow=(r[c]+8+j*s[c])%16
currnum=255-n[c]-32*j
RNGTable[16*currrow+c]=currnum
end
end
---------------------------------------------
--The above part is the good stuff. The following loop just tests that it works.
while true do
for i=0,15 do
for j=0,15 do
currval=RNGTable[16*i+j]
gui.text(20*j,9*i,currval)
end
end
vba.frameadvance()
end
I don't know if you want to go with the entry-by-entry table or this script. As far as I'm concerned, I think I'm done toying with the RNG. Discovering new patterns (if they even exist) should be extremely difficult.
Now I'll read through the last few posts a little more thoroughly.