![]() |
php question, best way for random numbers?
Whats the best way for random number generation?
this is what im using now Code:
<? |
not sure but im sure our channel coders will know :)
|
you dont need the mt_srand ((double) microtime() * 1000000);
Its build in in the mt_rand |
Quote:
mt_rand() will do for most purposes, but if you need pseudo-random data for purposes related to cryptography, keep in mind that mt_rand uses a mersenne twister, which is rather weak. So, in those cases, getting your pseudo-random data from /dev/urandom is a better option. |
Quote:
|
I believe that you don't really need to use mt_srand with php 5.2.1+
You could use uniqid as a seed, or data from /dev/random |
Quote:
|
im just getting a random number for random image headers, have 10 headers, want to rotate through them
|
Quote:
The other stuff only comes into play when dealing with things where security is an issue, like when a forgotten admin password of a site gets reset on request (which actually was a security hole in Joomla and WP). |
Quote:
$image = rand(1,10); echo "<img src=\"$image.jpg\" width=\"\" height=\"\" alt=\"\" />"; ?> :thumbsup |
Like above, rand() will work fine for what you need.
|
All times are GMT -7. The time now is 10:26 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123