Originally Posted By: DLively

Code:
random_num=random(100);
randomize();



Originally Posted By: Reconnoiter
ps: randomize is obsolete by the way and is replaced by random_seed wink.


Amongst other things. The code has a much bigger flaw, however: Reseeding the rng over and over again is bad.

The rng works by using the seed to seed its initial state, and on each "random()" invocation, the state is mutated. Lets assume for a second "random()" uses a good rng engine (Mersenne Twister), reseeding it over and over again takes entropy out of the result and also changes the quality of the produced random numbers, which will stop being uniformly distributed (if that was a quality of the rng to begin with). The long story is: You get very bad "random" numbers.

Even worse though: Usually the time is used as a seed, which is enough of an entropy source for most applications that don't require any cryptography. However, it's usually just the seconds that are taken, now, since random_seed() is a black box, it's a fair assumption that this is also the case here. What's bad about this, is that your function takes MUCH less than a second, which means: You seed the rng with the same seed over and over again.

This is a pseudo random number generator we are talking about here, there is no entropy system anywhere that feeds into it, it's absolutely deterministic if you know the seed. This means, seeding it the same seed over and over again means that it will generate the same numbers over and over again.

The bad thing about random numbers is that they stop being random once you look at them. Basically, you are robbing yourself of random numbers.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com