/    Sign up×
Community /Pin to ProfileBookmark

What would be the purpose of seeding srand with microseconds like in php manuals main example found here:
[url]http://us.php.net/manual/en/function.srand.php[/url] Please let me know, thank you.

[code=php]<?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(‘ ‘, microtime());
return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();
?> [/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 21.2007 — If you are using PHP 4.2.0 or later, there is no reason. If you are using an older version (hopefully not!), then its purpose is to "seed" the random number generator with a pseudo-random number (the current time in microseconds) so that each call to the script will result in a different sequence of random numbers from the rand() function. Again, this is a redundant waste of processing time in any reasonably recent version of PHP.
×

Success!

Help @vortexer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...