I am making a program and need a random number to select a feature. How do I generate a random number in PHP?
I am making a program and need a random number to select a feature. How do I generate a random number in PHP?
DirkFirst
Easy:
replace $min and $max with whatever you like.Code:<?php $min = 0; $max = 100; srand((double)microtime()*1000000); echo rand($min,$max); ?>
I forgot to mention, go here for more info:
http://www.php.net/manual/function.rand.php
RobSoftware:
All new versions of php (4+) no longer require srand before rand, it does it automaticly when rand is called.
So the new code would look like:
Code:<?php
$min = 0;
$max = 100;
echo rand($min,$max);
?>
I Need Help
bingo needhelp
Thank you guys
DirkFirst
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum