Page 1 of 1

Random seed generator

Posted: Wed Aug 22, 2012 2:22 am
by social_experiment
I'm looking for a random seed generator code snippet, to use with mt_srand(), so i'm using the one from the php manual

Code: Select all

<?php
list($usec, $sec) = explode(' ', microtime());
 return (float) $sec + ((float) $usec * 100000);
?>
My question/s
1. Is it good enough?
2. I don't want to use it directly from the manual (i guess security reasons) so if i change the 100000 value to something else, let's say 5000, will that increase / decrease it's effectiveness for generating random seed values?

Re: Random seed generator

Posted: Wed Aug 22, 2012 12:59 pm
by requinix
Unless you have a real security reason to generate your own seed (for which you'd have to do a lot better than just relying on the time) just let PHP seed it automatically (and randomly) for you. Identical seeds won't generate the same random number sequence anyways.

Re: Random seed generator

Posted: Wed Aug 22, 2012 4:50 pm
by social_experiment
cool; thanks for the reply