This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
anonimo182's profile picture

[QUESTION]True random number generator

Started by anonimo182, 14 November 2012 - 12:51 PM
anonimo182 #1
Posted 14 November 2012 - 01:51 PM
There is any true random generator in Lua that you know? Please help me with one :P/>/>

Thanks!
kazagistar #2
Posted 14 November 2012 - 02:03 PM
http://pgl.yoyo.org/luai/i/math.random

A true random number generator is not something you can easily achieve on a computer. Pseudo-random is good enough for all practical purposes.

EDIT: Just use the one I linked.
anonimo182 #3
Posted 14 November 2012 - 02:05 PM
ok, thanks anyways
itunes89 #4
Posted 14 November 2012 - 02:09 PM
math.random(min,max)
Easy :P/>/>
Lyqyd #5
Posted 14 November 2012 - 02:19 PM
math.random(min,max)
Easy :P/>/>

However, the question was in regards to a true random number generator, not a psuedo-random number generator.
Orwell #6
Posted 14 November 2012 - 02:42 PM
Unless you have a quantum computer or want to rely on user input (like mouse movements), you can forget about true random number generation. But the pseudo algorithms (like the one mentioned in this thread) should more than suit your needs. :P/>/>
anonimo182 #7
Posted 14 November 2012 - 02:59 PM
Thanks, I knew about the pseudo-random, I just wanted (if possible) a true random generator, but now I see is not possible… Thanks! :P/>/>
dissy #8
Posted 14 November 2012 - 03:00 PM
Unless you have a quantum computer or want to rely on user input (like mouse movements), you can forget about true random number generation. But the pseudo algorithms (like the one mentioned in this thread) should more than suit your needs. :P/>/>

This is off topic from the original posters question, but I've built a true random number generator out of parts from an old digital camera and a radioactive alpha partical emitter from a smoke detector. Of course this was at a time I did IT work for a group of developers who wrote encryption algorithms ;}

There are guides online for constructing them and as they work by detecting radioactive decay, assuming the standard model is correct, which specific particle will decay when is physically not possible to predict.


To the original poster, pseudo random numbers are more than good enough for anything you would be doing in Computercraft ;}

If you are interested in the theory behind such a device and "true" randomness, then you may enjoy this read:
http://www.inventgeek.com/Projects/alpharad/overview.aspx
Edited on 14 November 2012 - 02:07 PM
AndreWalia #9
Posted 19 November 2012 - 07:44 AM
i suppose you could make a true random number generator with 1. A hell lot of redstone (Ive seen videos of 1 random torch out of a number being lit) 2. Intermediate computrcraft coding and 3. an encoder built into the computer
Lyqyd #10
Posted 19 November 2012 - 07:51 AM
i suppose you could make a true random number generator with 1. A hell lot of redstone (Ive seen videos of 1 random torch out of a number being lit) 2. Intermediate computrcraft coding and 3. an encoder built into the computer

This still isn't a true RNG, since redstone is deterministic.
etopsirhc #11
Posted 19 November 2012 - 10:25 PM
use a chicken a pressure plate , and an enclosed space. instant random output , best coupled with a t-flip flop though. make 4 and you can generate 0-15 lol
Espen #12
Posted 20 November 2012 - 01:10 AM
use a chicken a pressure plate , and an enclosed space. instant random output , best coupled with a t-flip flop though. make 4 and you can generate 0-15 lol
Just because you can make a PRNG more complex doesn't mean it magically turns into a TRNG.
It gives the impression/illusion of not being deterministic, but it still is not getting any true random input from anywhere.
It's still just a salad of PRNGs. :(/>/>

That doesn't mean it's not enough though. It just depends on what one needs the random numbers for.
If real random numbers are not mission-critical, so to speak, then PRNGs are more than enough. And juggling around with them to get a different set of them is absolutely fine.

But for things like encryption, or computers trying to simulate real world phenomena (depending on type), etc. it is definitely not.
The reason for that is that computers are built similarly, and thus any "random" number they get by sole computation, without any "fresh" input from the outside, is theoretically repeatable by a computer that was built exactly the same (often not even that is necessary).

Just imagine a box with lego. If you don't add new pieces, then there are only so many shapes you can create with them.
Other boxes containing the same set of lego pieces can create the same shapes.
So to make sure you get unique shapes, you're gonna have to add some new pieces to the box (input from the outside world).

The example doesn't really fit comletely, but I hope it get's the main point across in a more visual way. :(/>/>