Do stateless random number generators exist?

A random number generator has a state — that’s actually a necessary feature. The next “random” number is a function of the previous number and the seed/state. The purists call them pseudo-random number generators. The numbers will pass statistical tests for randomness, but aren’t — actually — random. The sequence of random values is finite … Read more

How can I get a random number in Kotlin?

My suggestion would be an extension function on IntRange to create randoms like this: (0..10).random() TL;DR Kotlin >= 1.3, one Random for all platforms As of 1.3, Kotlin comes with its own multi-platform Random generator. It is described in this KEEP. The extension described below is now part of the Kotlin standard library, simply use … Read more

Generating uniform random numbers in Lua

You need to run math.randomseed() once before using math.random(), like this: math.randomseed(os.time()) From your comment that you saw the first number is still the same. This is caused by the implementation of random generator in some platforms. The solution is to pop some random numbers before using them for real: math.randomseed(os.time()) math.random(); math.random(); math.random() Note … Read more

How does a random number generator work?

There is also this algorithm: Oh, and more seriously: Random number generators use mathematical formulas that transfer set of numbers to another one. If, for example, you take a constant number N and another number n_0, and then take the value of n mod N (the modulo operator), you will get a new number n_1, … Read more

Non-repetitive random number in numpy

numpy.random.Generator.choice offers a replace argument to sample without replacement: from numpy.random import default_rng rng = default_rng() numbers = rng.choice(20, size=10, replace=False) If you’re on a pre-1.17 NumPy, without the Generator API, you can use random.sample() from the standard library: print(random.sample(range(20), 10)) You can also use numpy.random.shuffle() and slicing, but this will be less efficient: a … Read more