General > General Technical Chat
Odds seem too high when guessing random zeroes and ones
bookaboo:
It could be urban myth but the story is entirely plausible that in early generations of iPods Apple used a (for all intents and purposes) true RNG algorithm to choose songs. People complained that it wasn't random enough because it would play certain bands more than others, or in too long a consecutive sequence.
They modified it to be less (mathematically) random using weighting and balancing..... everybody happy.
bookaboo:
Would be easy enough to check the arduino RNG? Run a counter on that program for a few million iterations (without the delays obviously).
Add some variants and there's a YouTube video for someone to make.
SiliconWizard:
As to the random() function in Arduino, if the target is an AVR, then it's not from newlib, but from avr-libc, and the implementation can be seen here:
https://github.com/avrdudes/avr-libc/blob/main/libc/stdlib/random.c
It's not any better than the newlib one. It's similar, but actually probably slightly worse.
AndyBeez:
To prove the randomness of any random number generator, whether it is on a pocket calculator, a crypto cypher generator, or a national lottery supercomputer, you need to calculate the Standard Deviation of the random sequence. A pure random sequence between 0.0 and 1.0 will have a SD of exactly one-half. Any other number, even 0.501 or 0.49999999999 indicates bias or 'clustering'. Averaging over even a small sample set will show whether a bias exists.
OP : Maybe it's not random - it is a (crap) psuedo random algorithm - or your mind really is controlling the 8 bit realm?
Question for the EEs : would a noise diode on the analog pin provide a more randomised-random seed?
ejeffrey:
--- Quote from: RoGeorge on April 01, 2023, 08:32:58 am ---I always thought modulo division is the proper way to bound the randomness of a big number to a given range.
Are you saying that if we divide a big pseudo-random number by n, the remainder is no longer a pseudo-random [0..n)? I don't understand, why/how the randomness would be lost?
--- End quote ---
This depends strongly on the type of RNG. But for "traditional" algorithms like a linear congruential generator (still used especially where computing power is low and by lazy developers), you always want to use floor division rather than remainder. The reason is that these PRNGs use multiplication and addition, and the carry values propagate only to the left. If you do modulo division you are looking mostly at the low bits that often have much shorter cycles and have much more obvious patterns. In the extreme case if you use (prng() % 2) and the random number generator library is naively giving you the entire internal state as the random number, rather than only the most significant bits, you can get a "random" bit that always alternates 010101...
Note that I do not think this is the problem here. What is described is a well known cognitive bias, and even most very poor random number generators will produce sequences not easily noticed by humans playing a guessing game. But it is certainly possible to misuse a library PRNG and get extremely short cycles.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version