I'm working on an Arduino based dice, with just 6 LEDs. I'm generating a random number and the number should show as LEDs burning. But the random function in Arduino is not really random, it repeats itself. I've been looking into it and it seems that the solution isn't as easy as I thought. Is there any way I can make my random number real (or just a bit more) random? Any solution?
Random numbers will repeat. There has been a discussion on this recently. Try the search function at the top right of the screen to find more information.
Look up Mersenne Twister. (I'm not sure of spelling). You have room for at least a couple of hundred bytes of state.
You could also do the random in hardware, for example buying a geiger counter kit, timing the microseconds between clicks, and time%6 will be pretty random but needs testing thoroughly.
The key property of a source of randomness is that the output is
completely unpredictable (statistically), not that it looks random
to a human.
For a dice throw there's a 1/6 chance on each throw that its a repeat
of the last, just as there's 1/6 chance of any outcome. If the chance
of repeat were less than 1/6 then something is fishy with your dice!
ad2049q:
Look up Mersenne Twister. (I'm not sure of spelling). You have room for at least a couple of hundred bytes of state.
You could also do the random in hardware, for example buying a geiger counter kit, timing the microseconds between clicks, and time%6 will be pretty random but needs testing thoroughly.
But don't time it in milliseconds, millis() is rather biased as sometimes it jumps
2 steps. micros() probably has some slight bias too (look how its coded).
A better approach is to look at each pair of timings and generate a 0 if the first
is longer, a 1 if the second is longer. Reverse the sense each time. This is the easiest
way to generate unbiased bits from a source of randomly timed events. Hotbits uses
it I believe. HotBits: Genuine Random Numbers
i wouldn't it be simple to just loop trough 1-6 as fast as possible, and stay on the one that you currently have when the user presses the button? the user pressing the button is one of the most random things you have, and is so easily used for this. and when looping full speed, there is no way for the user to manipulate the result by careful timing.
racemaniac:
i wouldn't it be simple to just loop trough 1-6 as fast as possible, and stay on the one that you currently have when the user presses the button? the user pressing the button is one of the most random things you have, and is so easily used for this. and when looping full speed, there is no way for the user to manipulate the result by careful timing.
Unlike, for instance, a roulette wheel... See a book called "The Newtonian Casino" for
details