Random seed generator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Random seed generator

Post 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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Random seed generator

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Random seed generator

Post by social_experiment »

cool; thanks for the reply
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply