random number generator in php?
Please help me how can i generate random number in php? please share any related script or suggest me.
Thanks for reply.
Not a random number, but at least a DIFFERENT number can be generated by the time() function. This returns the number of seconds since Jan 1st 1970 00:00:00 hrs.
This counter changes every second, and you could make it appear more random. How complicated the algorithm needs to be depends upon how many unique outputs are required. E.g. If the outputs are "yes", "no" and "maybe", which just need to appear random, then the last digit can be used to point to an offset (modulo 9) from the present position in a string of 9 characters "y", "n" and "m" e.g. $sequence="nymynmmny".
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
print rand() . "<br>";
//generates and prints a random number
print rand(10, 30);
//generates and prints a random number between 10 and 30 (10 and 30 ARE included)
print rand(1, 1000000);
//generates and prints a random number between on and one million
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)