I am making a program and need a random number to select a feature. How do I generate a random number in PHP?
I need to generate a random number in PHP
Started by dirkfirst, Jun 19 2006 02:01 PM
7 replies to this topic
#1
Posted 19 June 2006 - 02:01 PM
|
|
|
#2
Posted 19 June 2006 - 03:42 PM
Easy:
replace $min and $max with whatever you like.
<?php $min = 0; $max = 100; srand((double)microtime()*1000000); echo rand($min,$max); ?>
replace $min and $max with whatever you like.
#3
Posted 19 June 2006 - 03:49 PM
#4
Posted 20 June 2006 - 05:01 AM
RobSoftware:
All new versions of php (4+) no longer require srand before rand, it does it automaticly when rand is called.
All new versions of php (4+) no longer require srand before rand, it does it automaticly when rand is called.
#5
Guest_NeedHelp_*
Posted 22 June 2006 - 11:34 AM
Guest_NeedHelp_*
So the new code would look like:
<?php $min = 0; $max = 100; echo rand($min,$max); ?>
#6
Posted 22 June 2006 - 11:54 AM
bingo needhelp
#7
Posted 29 June 2006 - 08:59 AM
Thank you guys
#8
Guest_Kaabi_*
Posted 05 July 2006 - 06:58 PM
Guest_Kaabi_*
That second code looks much better than the first code. I once wrote a random name generator in C++ (I don't remember how to now, it was when I was trying to learn C++), and it was pretty cool, I only used it once.


Sign In
Create Account


Back to top









