Need help with ONE line :)

Hey guys

I’ve tried figuring it out to no avail. Could someone please explain to me what exactly this particular line of code means?

I have looked on the php manual for the function srand, but it seems pretty obselete?

Any help would be appreciated.

srand ((double)microtime()*1000000);

microtime — Return current Unix timestamp with microseconds

It itself has bool $get_as_float ] parameter which u can pass but you are type casting it as float manually

if floated then a float (in seconds) is returned.

if not this function returns the string “msec sec” where sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT), and msec is the microseconds part. Both portions of the string are returned in units of seconds.

srand -Seeds the random number generator with seed or with a random value if no seed is given.

so in total it is generating a large random number to be used in some case.

I dont see much benefit of mulitipying by constant itself…but may be you need some large number for some case…so it is being done

Making that number odd rather than even(1000000) can come handy in some case

source: php.net is your fren

Oh ok I get you. Thanks for that Frank :slight_smile:

@OP: please note that, since PHP 4.2, PHP seeds the RNG automatically, so you don’t have to call [srand() or [URL="http://php.net/mt_srand"]mt_srand()](http://php.net/srand).

But it’s important to note that all casting does, in this case, is get the microseconds. The elapsed seconds since the Epoch gets discarded from the value yielded by the expression. However, it looks like that’s probably what the original author intended, even though it’s not strictly necessary.

Making that number odd rather than even(1000000) can come handy in some case

Just curious, what do you mean here? It seems to me, the original author simply scaled up the value so it could be interpreted as an integer.

Yeah I realized that hence the “but it seems pretty obsolete?”.

Since that sentence ended in a question mark, it seemed you weren’t sure, so I thought I’d state explicitly that it is obsolete, and why.

when i say that i mean using odd PRIME number is better than using even number(lol …sometime single word make a huge difference…i missed word PRIME there…:slight_smile: )

http://www.php.net/manual/en/function.srand.php#21052
http://www.php.net/manual/en/function.srand.php#48652
http://www.php.net/manual/en/function.srand.php#43277

Ah okay, thanks for clarifying. In this case, though, I don’t think the seed is so much an issue, but the RNG itself (rand()). As one of the user comments notes, using a better RNG, like the Mersenne-Twister, will be more helpful. In some cases, you might even use an external source of entropy.