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!
$rand = rand(1,5);
if($rand == 2){
// do some stuff
}
this is a code im using for an april fools day joke ( i load an error page - really smurfs people off ) however it seems to load like 1 out of 30 pages loads.
are the results cached or something?
I realize mt_rand() is 4 times faster, but does it mean that rand() isn't as random?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
This of course is based on no testing, but I think this is a case of red-car-syndrome. You look out for something to happen, it happens a whole lot more often than it should. Run a test, keeping track of the values of the rand() call.
rand() and mt_rand() are both pseudo-random functions. They are math progressions that eventually wrap given enough calls. mt_rand has a MUCH longer span than rand, but it will eventually start repeating.
Sadly, there are few real random sources available (although technically, most CPU's has a few sources for ~truely random data -- although not labeled as such).
Overall, random in a computer is anything but random.
not worthy of testing, as it was my 20 second script to try to annoy people as much as possible with as little effort as possible
however, just refreshing pages I should get the desired result one out of every 5 page loads. its a far cry from that currently
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mt_srand(hexdec(substr(md5(microtime()), -8)) & 0x7fffffff); // create a new random seed based off the system clock
$rand = mt_rand(1,5);
if($rand == 2){
// do some stuff
}
You will find the randomization is far more random. If you do not use a seed value the random function will use the same seed point and things will not be that random.