Random Numbers
Moderator: General Moderators
-
bobthebobert
- Forum Commoner
- Posts: 25
- Joined: Sat Feb 15, 2003 5:56 pm
Random Numbers
How do you do them in PHP?
-
phpfreak
- Forum Commoner
- Posts: 30
- Joined: Fri Mar 21, 2003 10:28 am
- Location: New Jersey,USA
- Contact:
random function in php
hi there,
the following script generates 10 numbers randomly from 1-10
<?php
$count=0;
while ($count!=10)
{
$number=rand(1,10);
//rand is the random function and it chooses between number 1 and 10
//(inclusive of themseleves)
echo "the number now is: $number";
echo "<br>";
$count=$count+1;
}
?>
hope it helped!!!
the following script generates 10 numbers randomly from 1-10
<?php
$count=0;
while ($count!=10)
{
$number=rand(1,10);
//rand is the random function and it chooses between number 1 and 10
//(inclusive of themseleves)
echo "the number now is: $number";
echo "<br>";
$count=$count+1;
}
?>
hope it helped!!!
but keep in mind
http://www.php.net/manual/en/function.rand.php wrote: In older versions of PHP, you had to seed the random number generator before use with srand(). Since 4.2.0 this is no longer necessary.
-
bobthebobert
- Forum Commoner
- Posts: 25
- Joined: Sat Feb 15, 2003 5:56 pm
int rand ( [int min, int max])
yes, you can do that, but no fraction.
yes, you can do that, but no fraction.