So, it gets the seconds of the system clock and then randomizes a number from there or what?
Results 1 to 2 of 2
- 12 Jan. 2011 04:14am #1
Can't get my head around srand(time(0))
- 12 Jan. 2011 05:28am #2
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 18.25
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.