how does random() actually work?

The entire first chapter of Donald Knuth’s seminal work Seminumerical Algorithms is taken up with the subject of random number generation. I really don’t think an SO answer is going to come close to describing the issues involved. Read the book.

How to test random numbers?

With most tests you can supply a large file of random numbers (integer or floating point) and run various tests on that sample file. DIEHARD worked that way, if I remember correctly and some others do, too. If you really want to see your generator fail, you could try using TestU01 by Pierre L’Ecuyer which … Read more

How to get truly random data, not random data fed into a PRNG seed like CSRNG’s do?

As you know, “truly random” means each of the bits is independent of everything else as well as uniformly distributed. However, this ideal is hard, if not impossible, to achieve in practice. In general, the closest way to get “truly random data” in practice is to gather hard-to-guess bits from nondeterministic sources, then condense those … Read more

Lua math.random not working

You need to run math.randomseed() once before using math.random(), like this: math.randomseed(os.time()) One possible problem is that the first number may not be so “randomized” in some platforms. So a better solution is to pop some random number before using them for real: math.randomseed(os.time()) math.random(); math.random(); math.random() Reference: Lua Math Library