IGNORED

graphing random numbers

Recommended Posts

if you haven't been following along I come from here

this let's you choose among 20 possible (random number) routines and graphs the

result as a sort of bar graph

the routines are r0..r19

they should return a number in temp1

the numbers are modded to 0..31

the number of times a number comes up is a bar at

that position of the playfield. the height is limited to 20

the numbers are left to right 0..31

the routine is called each drawscreen untill results for

255 numbers have been graphed

it then waits for you to press fire at which point rand is reseeded from

a counter and it runs through another 255 numbers

while it's waiting for you to press fire you can step through

the routines to select one of r0..r19 using joy0up-down

the number of the routine should be displayed in the score

(but RT didn't seem to be able to see it)

in order to get a contiguous 32 bytes of RAM to keep track of how often a number comes up

I moved playfieldpos to aux1 (\$F0) in 2600basic.h

r0 is just rand

r1 is RT's scheme for numbers 0..26

r2 starts with 5 bit random numbers (rand & 31) and scales that to 0..26

r3 starts with 7 bit random numbers (rand / 2) and scales that to 0..26

r4 starts with 8 bit random numbers and scales them to 0..26

r5 starts with 8 bit random numbers and scales them to 0..26 but uses 16 bit math

r6 starts with 16 bit random numbers (it calls rand twice to get 16 bits) and scales to 0..26 using 16 bit math

r7 starts with 5 bit numbers from the upper 5 bits of rand (rand & &F8) and scales them to 0..26 using 16 bit math

r8 takes rand & 31 mod 27 carrying the residue along to eliminate/distribute the bias that modding causes and so needs a variable

r9 is rand & 26

r10 is rand & 15

r11 is rand & 240 shifted to 0..15 same as r10 but using the upper 4 bits instead of the lower 4 bits

r12 if you scale 5 numbers down to 4 then one of the four will get the spare ie three of the four will come up once and one twice

if you scale 0..255 to 0..204 then every fourth number should come up twice as often but any four contiguous values should

come up as often as any other contigouous four

if you divide the numbers by 4 then each bar should subsume four contigous values and have equal distribution

thats what r12 and 13 do, r12 scales 7 bit random numbers to 0..204 and keeps only results that are 40..71

r13 is the same as r12 but divides by 4 and so hides the biases, it keeps 10..41

r14 and 15 are the same as r12 and 13 but uses asm and 8 bit random numbers

r16 is meant to be a worst case of RT's scheme for numbers 0..57 and shows the left side 0..31

r17 is the same but shows the middle 13..44

r18 is the same but shows the right edge 26..57

r19 rand & 30 ie even numbers 0..30

graph_rand0006.bas

graph_rand0006.bas.bin

Share on other sites

So when you run that .bin file, you see numbers in the score? I'm using Stella 4.6. Do I need a newer version to see the numbers in the score?

Share on other sites

So when you run that .bin file, you see numbers in the score? I'm using Stella 4.6. Do I need a newer version to see the numbers in the score?

the score should show the number of the routine selected ie something in the range 0..19

I'm using Stella 4.5

I wonder if anyone else is having problems

Edited by bogax
Share on other sites

I made a quick program that shows numbers in the score using code that you provided years ago:

rand_test_2016y_10m_01d_2259t.bin

rand_test_2016y_10m_01d_2259t.bas

In this program, the first row on the screen gets a pixel, then the next row gets a pixel and it goes like that until it hits the bottom and starts back at the top. Press the fire button to switch to a different version. Pressing the reset switch will reset the program.

Version 1 is (rand&31)

Version 2 is (rand/8)

Version 3 is (rand&15) + (rand&15)

Version 4 is (rand&15) + (rand/16)

Version 5 is (rand/16) + (rand/16)

Share on other sites

So when you run that .bin file, you see numbers in the score? I'm using Stella 4.6. Do I need a newer version to see the numbers in the score?

When the screen is finished drawing all the blocks from test 0, and you press up or down on the joystick, does the score change?

Share on other sites

When the screen is finished drawing all the blocks from test 0, and you press up or down on the joystick, does the score change?

Thanks. I thought pressing the fire button by itself was supposed to switch to the next number. You have to press up or down, then press the fire button. My ADD/LD brain must have misunderstood the instructions again.

Share on other sites

first, I rigged it so it just stashes playfieldpos in aux1 then put it back when it's time to draw the screen

so you don't need to modify the defintion of playfieldpos

I fixed it so you can choose between the 8 bit rand and the 16 bit rand

I added a (not very good) LCG and a scatter table

you choose amongst the options with joy0 left-right

the two digits on the left tell you where you are

bit 0 of the right digit selects between rand8 and rand 16

bit 1 of the right digit turns on the LCG

bit 2 of the right digit applies the scatter table

if bit 3 is set you get just the LCG

bit 0 of the left digit turns reseeding on or off 0 for off 1 for on

even numbers except 8 or 18 are 8 bit rand odd numbers are 16 bit rand

if the left digit is 0 then it uses the same seed if it's 1 it reseeds

if the LCG is selected it is XORed with the rand result unless the number is 8 or 18 in which case you just get the LCG

so 2,12, 3, 13 are rand XORed with just the LCG

if the LCG is on and the scatter table is enabled then it takes the result of rand ^ LCG and looks up a number in the table and returns that

if the LCG is off it XORs rand with the current seed and returns that and then uses it to look up a new seed

so 4, 14, 5, 15 are rand ^ scattertable

6, 16, 7, 17 are rand ^ LCG then lookup value in scattertable

8, 18 are just the LCG

if reseeding is not selected the seed is restored to whatever it was (so you can run different combinations with the same seed)

then it does a run of 255 and displays it

if reseeding is selected it reseeds rand and the LCG from the current seed and the scatter table (so even thought there's three bytes

there's only 256 possibilities)

the scatter table was lifted from the wikipedia entry on Pearson hashing

graph_rand0008.bas

graph_rand0008.bas.bin

Edited by bogax
Share on other sites

almost done

I was thinking of integrating a scatter plot function

and maybe a modified score kernel-minikernel to make

something less cryptic than numbers for the

random number selection

fixed some more bugs

moved some other stuff to subroutines

graph_rand0010.bas

graph_rand0010.bas.bin

Share on other sites

the scatter plot plots a pixel with x = the previous number and y = the current number

it should work now with routines 0..99 although it still has the same 20

you'd need to add a routine and change the Number_of_Rand_Routines constant

and change the on_gosub that selects amongst the routines

rearranged the function selection

now you move right and left to select a function and use up_down to change it

there's an indicator for what you're doing/where you are

the indicator is just a character or two over the score digits

the three score digits on the left are

R reseeding enable

S scatter table enable

L LCG enable

1 is enabled 0 disabled

the fourth digit from the left is the rand select

R8 0 for 8 bit rand

16 1 for rand 16

L 2 for the LCG

the two digits on the right are the routine select number

if the rand digit is 2 for the LCG that's all you get (no rand8 or rand16)

if LCG is selected the LCG enable bit is set (but has no effect)

and if the scatter table is enabled it will look up a number using the LCG result (which it didn't do before)

otherwise the same

rand8 or rand16 get XORed with the LCG if it's enabled

the result is run through the scatter table if it's enabled

if the LCG is enabled the scatter function just looks up a new value in the scatter table

if LCG is disabled it XORs with the previous MyRandSeed value and returns that and

uses the result to look up a new MyRandSeed value to XOR with next time (no particular reason for the lag)

to switch between histogram and scatter plot hold the joy0fire and the mode will toggle every 2 seconds

as indicated by the score color.

whatever you release fire on is what you get

I also added a bunch of extra wordy names to the code for RT (but no leading under scores, you've got to draw the line somwhere )

edit: fixed a couple bugs

now it's perfect so I expect this to be the final version

graph_rand0012.bas

graph_rand0012.bas.bin

Edited by bogax

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.