rhd
0
- Joined
- Dec 7, 2010
- Messages
- 8,469
- Points
- 0
Does it really need to be THAT random? After all you've only got 7 colour choices, which is going to be far more limiting than the actual randomness.
Here's how I'd do it:
In the main loop, use say, the first button press to store a value from millis(), and use that as a seed for the RNG. Run the RNG with that seed, to generate a value from 1-7, and store that in EEPROM. On next startup, simply use that EEPROM value as the first randomized colour choice. By doing this you're using the randomness of the user (there is no way they'll be able to get the button press accurate to the millisecond every time).
The seed is just an arbitrary number that is used as the basis of the RNG, so increasing the seed by 1 does not neccesarily mean the RNG's output will just increase by 1 also, it COULD be, but it's also just as likely it'll be a totally different number to whatever the previous seed was. Even if they press the button within 1 second every time, you've got the chance of 1000 different seeds, which is far more than the possible 7 colour combinations you can even use
Here's the problem.
The second, third, fourth, etc time around, there is no button press. The randomness happens immediately upon startup. Remember that this circuit is powering off and starting back up again.
So suppose the previous color was 4, and you increment it by 1 to get 5, which becomes the new seed. If 5 goes into the RNG immediately upon startup, it would be expected to result in the same output any time 5 goes into the RNG immediately upon startup, because nothing is different from one time to the next (remember, no additional button presses come into play).
That means color 4 will always lead to the same color next, because color 4 will always go into the EEPROM, and then increment to 5 on startup, which will go into the RNG at the exact same time.
Does that make sense?
-----
Got the board done - this was a painful one:
Attachments
Last edited: