If you want to start an argument in certain circles, claim to have a random number generation algorithm. Turns out that producing real random numbers is hard, which is why people often turn to strange methods and still, sometimes, don’t get it right. [Hillel Wayne] wanted to get a “good enough” method that could be done without a computer and found the answer in an old Usenet post from random number guru [George Marsaglia].
The algorithm is simple. Pick a two-digit number — ahem — at random. OK, so you still have to pick a starting number. To get the next number, take the top digit, add six, and then multiply by the bottom digit. So in C: n1=(n/10+6)*(n%10). Then use the last digit as your random number from 0 to 9. Why does it work? To answer that, the post shows some Raku code to investigate the behavior.
In particular, where does the magic number 6 come into play? The computer program notes that not any number works well there. For example, if you used 4 instead of 6 and then started with 13, all your random digits would be 3. Not really all that random! However, 6 is just a handy number. If you don’t mind a little extra math, there are better choices, like 50.
If you think humans are good at picking random numbers, ask someone to pick a number between 1 and 4 and press them to do it quickly. Nearly always (nearly) they will pick 2. However, don’t be surprised when some people pick 141. Not everyone does well under pressure.
If you want super random numbers, try a lava lamp. Or grab some 555s and a few Nixie tubes.
https://xkcd.com/221/
Or use a real dice?
Humans are just terrible at generating random numbers, and there is also no proof about the randomness of numbers generated by humans. That is why things like dice and coin flipping have been invented.
Can you imagine a dice game where the dice are replaced by a human making up “random” numbers? That probably turns very ugly very quickly. It may be an interting experiment as a proof of concept.
I like the meme where it’s a random number function in C that just creates an unassigned variable and returns that.
Nitpick: It’s one die, two dice.
English is weird.
We should add an olympic sport where people compete by trying to pick the most random number sequences.
“Can you imagine a dice game where the dice are replaced by a human making up “random” numbers?”
Yes! You can replace die rolls in table-top roleplaying games with the following algorithm:
1. The DM asks a player to “roll” a die (in this example, a D20).
2. The player and DM each secretly choose a number between 1 and 20.
3. The player says their number out loud, followed by the DM. The numbers are added together. If the result is larger than 20, then 20 is subtracted from the result (equivalent to ((P + D – 1) % 20) + 1).
This works because of the adversarial nature of this type of die roll. It’s equivalent to a game of rock-paper-scissors with more than three outcomes. It isn’t *random*, but it is *fair*.
At that rate, the DM could cause a failure or even critical fumble anytime they want…
The idea is interesting though, perhaps both write down a number and show it at the same time?
Why not just use the number to represent a position in the prime list then multiply by it and do the same thing again 4 more times…eg 23 = 2+3 =5. The fifth prime number is 11. 23×11 = 253. Take the last 2 numbers and do the same thing again. 5+3=8 prime 19 x 53 = 1041…etc. Have the code spirit incantate the first random number and base the prime multiplications with that holy rolling number to produce elysium. Can I get an amen.
One interesting thing is all primes are odd so the outcome would always be odd (or even) if the original number was odd (or even).
I’ll probably get ripped for all this, but primes and pi seem perfect to mix In to generating randoms, as spi is infinite therefore pulling numbers from the float stack seem viable. Hell IDK.
This part of the article does not make sense:
“For example, if you used 4 instead of 6 and then started with 13, all your random digits would be 3.”
For one thing, no matter which magic number you used or which two digit number you picked, the random digit would always be the same for those two choices.
Yes, but with the number 4 picked as multiplier and 13 as a seed you are stuck at 3 i.e. all your random digits are ‘3’, with multiplier 6 you will have longer sequence: 13, 19, 55, 35, 33…
To laymen, “random” means “pseudo random” and not “true random”. It always has and likely always will.
There is no argument about it, what they are doing is called trolling and being anti-social. Please don’t dignify it as anything else.
I don’t think the laymen really know the difference between “pseudo random” and not “true random”, so I find it hard to believe that a layman talking about randomness is specifically referring to “pseudo random”.
When laymen use the term random they simply don’t specify the type of randomness.
https://xkcd.com/221/
Flip a coin until you have a binary value long enough for your needs
Why not roll some dices?
https://www.youtube.com/watch?v=7n8LNxGbZbs
What is the best way currently to generate gigabytes or terabytes of cryptographically secure “true random” numbers in a reasonable span of time. And I do not mean feeding a low entropy source into hashing algorithms to increase or bulk out the bitrate while hiding an inherently weak source of true randomness.
Point a lot of sensors at a chaotic physical process. Atmospheric sensors and cameras pointed at lava lamps are two examples of such.
Geiger tube and something suitably hot to get the time as low as you need.
The latest super fast “T”RNGs generally use lasers, and they’re designed from the ground up to have certain chaotic optical properties (so you can’t just DIY this sort of thing), though this speed tradeoff is considered “not a good enough guarantee of randomness” in certain cases hence the also very active research into QRNGs (which are currently super slow but have unique benefits like actually being able to validate your QRNG’s output against known probabilistic quantum properties)…
On the more accessible side, one maybe cool RNG project I’ve been thinking about doing as a hobbyist is using laser speckle (that “grain” you see when a laser dot reflects off a wall, which is purely a result of interference from wavelength-scale surface roughness since all photons are by definition coherent in a laser).
The idea was to use a cuvette filled with silicone oil of the right viscosity, and a dispersion of aluminum oxide nanoparticles (polishing powder + ultrasonic cleaner). One side of the cuvette has a webcam with proper filtering, and at the other side you shoot a 5mW red laser. Assuming good enough resolution, shutter speed, framerates, proper viscosity, and dispersion, you can theoretically end up with a system where Brownian motion causes a constant chaotic evolution in 3D that’s then projected onto 2D speckle. Just needs to be tuned right mechanically so the dispersion never settles, and probably some thermal shielding for stability. Now I know there are some algorithms that can reverse this type of embedding to an extent (after all speckle is mostly used for imaging), but the point is that whatever entropy you get from the Brownian motion is well extracted into the speckle after a few frames, and you still can’t simulate the evolution of such a chaotic system outside of starting with complete information especially if there’s a ~30FPS entropy pool constantly being whitened by new video frames and used indirectly in some sane manner.
Anyone know if this would be worth trying as a side project? I’m not rolling my own crypto haha, just a fun idea.
Your interpretation of the article says, “take the top digit, add six, and then multiply by the bottom digit. So in C: n1=(n/10+6)*(n%10). Then use the last digit as your random number from 0 to 9,” but the original article says, “Choose a 2-digit number, say 23, your “seed”. Form a new 2-digit number: the 10’s digit plus 6 times the units digit. The example sequence is 23 –> 20 –> 02 –> 12 –> 13 –> 19 –> 55 –> 35 –> … and its period is the order of the multiplier, 6, in the group of residues relatively prime to the modulus, 10. (59 in this case). The “random digits” are the units digits of the 2-digit numbers, ie, 3,0,2,2,3,9,5,… the sequence mod 10.”
function newr = rx (a)
newr = floor (a / 10) + mod (a, 10) * 6;
endfunction
in matlab. In C it would be a/10+(a%10)*6 , a little different operation order
Yeah, HaD’s description of the algorithm confused me when I read the linked article. “How did they get 20? I get 24?” But working it the other way, multiplying the units by 6 then adding the tens, cleared it up.
“Hotbits: genuine random numbers generated by radioactive decay”, an online service provided by John Walker (one of the founders of Autodesk), from 1996 to 2022. More info at https://www.fourmilab.ch/hotbits/
“Brain And Brain! What Is Brain?!”
Worst. Episode. Ever.
And yet I smile everything I watch it. You might say it’s a giver of pain and delight.
the esp32 is bad for random, as it uses random wifi signal stuff to generate bits. I’ve seen a few papers we people have tested the output – not an easy thing to do – and it came out looking OK.
This is probably just a “me” problem.. but when I pick a “two digit number”, let’s say [31], the next step is to pick the “top digit”.. what is the top digit? 3?
I believe generating prng numbers using math is way faster than most of the physical options others have pointed out here. The problem is that they are often detectable and predictable. I tried solving for that with a kernel module I wrote to replace /dev/urandom. At a very high level, I use two different prngs xor’d together and shuffled by a third prng. https://github.com/josenk/srandom