Good pseudo random number generator in 8080??

55 views
Skip to first unread message

Patrick Jackson

unread,
Jun 7, 2024, 3:23:53 PMJun 7
to Altair-Duino
I'm trying to make a 2048 game in 8080 assembly, and I'm stuck on a bit where I want to place a random tile of '2' every time you hit a key.
Right now, it searches through a list of 16 numbers. If it is a ZERO, then its an open space and I can place a 1 there ('2' in the lookup table). If not a 0, then there's something there. If so, increment your random number (counter incremented by waiting for a user to hit a key) and try again.

Right now, the code isn't a game but every time you hit a key ('q' quits) it will choose a random tile and place a 2. But as the board slowly fills up and less tiles are available, the game reaches a state where the remaining handful of tiles are impossible to reach given 1) your random seed and 2) the algorithm I use to increment the seed pseudorandomly. How can I fix this?

Code (simple cp/m asm/load will build it):

https://pastebin.com/pYE1mAgD

John Galt

unread,
Jun 7, 2024, 3:47:15 PMJun 7
to Altair-Duino
since the placement is based on a keypress. what you can do is run a counter around the keypress, then the seed will depend on when the key is pressed, each time will be a little different.
many original random generators revolved around noise in the ram on start up. but everything kind of resets itself to a known state and it makes randomness not so random.

what i did in a dice program i wrote was when the program loads it gives you a little blurb and waits for a keypress. the idea was distract you a little so you take a little time to hit the key that generates the first random seed and starts the dice program.
then i added a second seed when you re-roll the dice together with the first seed. so you get decent randomization.

all that bit shifting and grabbing a piece of memory or a sector from a disk ends up being not so random and usual repeatable.

In machines where you have a Real time clock then you would take the time down to the 1/60th of a second and generate the seed from that.

Mark Rosenthal

unread,
Jun 7, 2024, 3:51:47 PMJun 7
to John Galt, Altair-Duino
I don't think it's about the generator.  I think it's about selecting from the remaining population, regardless how small it is.  So if the remaining population  is 2, The only possible results are 1 or 2.

--
You received this message because you are subscribed to the Google Groups "Altair-Duino" group.
To unsubscribe from this group and stop receiving emails from it, send an email to altair-duino...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/altair-duino/8f306caa-44a5-4c70-81d0-64821fcbb4a9n%40googlegroups.com.

Patrick Jackson

unread,
Jun 8, 2024, 12:46:07 AMJun 8
to Altair-Duino
I solved it (shelved the problem of creating a real twister algorithm) by just "if the random number won't work, increment it until it will"
Reply all
Reply to author
Forward
0 new messages