A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

Can't get my head around srand(time(0))

922 views · started by NotNeccesary ·
#1
Can't get my head around srand(time(0))
So, it gets the seconds of the system clock and then randomizes a number from there or what? :|
#2
True randomization cannot be achieved by an RNG (Random number generation - Wikipedia, the free encyclopedia) which is what PHP uses to generate random integers.

What you are doing is "seeding" the RNG so that it creates an integer based on the current amount of milliseconds have passed since base date until now.

Basically the RNG will determine an integer randomly with an algorithm, we can add in the current milliseconds so that that result is based on the current time, meaning that in the next run it is impossible to have the same seed as used previously. Therefore making the algorithm a little more solid.

But seeding with time ( ) is no longer needed since version 4.2, srand will automatically be seeded with the time. Making it pointless to seed with time.