Posted By: HeelX
how to randomize properly - 07/19/14 11:33
random_seed((sys_seconds % sys_month) * sys_hours - 42);
Posted By: 3run
Re: how to randomize properly - 07/19/14 12:14
Thank you! I wish this could be add in the manual!
Posted By: DLively
Re: how to randomize properly - 07/19/14 13:00
I dont understand, how is this different or better than just random_seed(0);?
Posted By: HeelX
Re: how to randomize properly - 07/19/14 14:36
It is derived from the Z12 and Z5 strategies. Therefore you should trust it.
Posted By: DLively
Re: how to randomize properly - 07/19/14 15:51
Alright, I shall trust it - But how its different than random_seed(0);
Posted By: WretchedSid
Re: how to randomize properly - 07/20/14 17:53
It's not implementation defined.
Anyhow, this is not the right way to initialize a PRNG, sorry lads. Time doesn't have enough entropy and even worse, because this code only takes seconds, you have a full second (or 2.something billion CPU clock cycles) where re-seeding the PRNG will result in it generating the very same values over and over again.
The generally agreed upon way of seeding a PRNG is to tap into the kernels entropy pool and get some bits out of there. The kernel has a pool of high quality entropy available for access, and it's ideal to get some bits from there to initialize a PRNG.
Edit: to be fair, going down this road leads you to all kinds of interesting topics. It also highly depends on what quality of randomness you require. A game might get away with very low quality randomness out of a shitty LCG, although it really doesn't hurt to use Mersenne Twister which has a much larger period and returns uniformly distributed results. But maybe you don't want uniformly distributed results but add a weight in, for example RPGs might choose to have a "luck" skill that biases the results of the randomness.
Posted By: DLively
Re: how to randomize properly - 07/20/14 18:06
Thanks for clearing this up, JustSid