Jump to content
IGNORED

Seeding rand


Cybearg

Recommended Posts

In my multicart, I have had issues in the past where the random number generator seems to break between game banks. RevEng, I believe, recommended that I set T1024T=rand before exiting each game.

 

I have been seeding rand in some games with if joy0fire then rand=counter, with counter being a variable that just increments once per frame.

 

A potential issue here is that rand could, in a 1 in 256 chance, be set to 0, which breaks the random number generator and would then push that brokenness into the T1024T and break all random numbers until the 2600 was powered off and on. Furthermore, the same could happen if the rand of T1024T=rand happens to roll a 0.

 

Am I incorrect in this concern? I was reading the documentation for 7800basic (very excited) and noticed this brought up, which reminded me that this was an issue for the 2600 as well. How should I seend rand and T1024T without possibly breaking anything?

Link to comment
Share on other sites

When bB starts up it reads in the timer value, binary ORs it with 1, and uses that as the random seed. Because the timer is in a random state during power-up, it's a more or less random value.

 

Your multicart menu had the effect of messing up this scheme, as it allowed the timer to run down to 0 long before the games were selected and started. This is why I suggested you store a rand value in T1024T when exiting the menu into a game, and also when you exited games back to the menu - to keep the rand sequence alive.

 

If you're using a counter to time some human interaction to further seed rand - not a bad idea - you do indeed need to ensure it's not 0 before storing it in rand. Either use an if...then in that case or use "rand = counter | 1".

Link to comment
Share on other sites

If you're using a counter to time some human interaction to further seed rand - not a bad idea - you do indeed need to ensure it's not 0 before storing it in rand. Either use an if...then in that case or use "rand = counter | 1".

I'm fairly certain it was your idea, as I highly doubt I would think of something that clever.

 

Noted. The issue is that none of my games have the space to afford even that if statement to ensure no zero is seeded. I'll just need to leave it at rand, then.

Edited by Cybearg
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...