Should I use `random.seed` or `numpy.random.seed` to control random number generation in `scikit-learn`?

Should I use np.random.seed or random.seed? That depends on whether in your code you are using numpy’s random number generator or the one in random. The random number generators in numpy.random and random have totally separate internal states, so numpy.random.seed() will not affect the random sequences produced by random.random(), and likewise random.seed() will not affect … 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

Is there an alternative to using time to seed a random number generation?

The rdtsc instruction is a pretty reliable (and random) seed. In Windows it’s accessible via the __rdtsc() intrinsic. In GNU C, it’s accessible via: unsigned long long rdtsc(){ unsigned int lo,hi; __asm__ __volatile__ (“rdtsc” : “=a” (lo), “=d” (hi)); return ((unsigned long long)hi << 32) | lo; } The instruction measures the total pseudo-cycles since … Read more

random.seed(): What does it do?

Pseudo-random number generators work by performing some operation on a value. Generally this value is the previous number generated by the generator. However, the first time you use the generator, there is no previous value. Seeding a pseudo-random number generator gives it its first “previous” value. Each seed value will correspond to a sequence of … Read more