Here we have a simply PHP Lottery Number Generator. The script will generate 6 unique numbers from 1 to 49. This was designed for the UK National Lottery but only takes a few seconds to edit for other lotteries.
To change the quantity of numbers you would like to generate, change the 6 on this line to however many numbers you need:
while (count($numbers) < 6) {
To increase the maximum number, change the 49 on both of these lines:
$randomn = rand(1, 49);
<?php
$x = 0;
$numbers[0] = 0;
while (count($numbers) < 6) {
$randomn = rand(1, 49);
while(in_array($randomn, $numbers)) {
$randomn = rand(1, 49);
}
$numbers[$x] = $randomn;
$x++;
echo "Number $x is: $randomn.<br />";
}
?>
Tip: To edit this script for the EuroMillions, simply copy and paste the whole script twice. On the second paste just edit the while loop from 6 to 2, and the rand from 49 to 9.
Showing posts with label PHP Random Number. Show all posts
Showing posts with label PHP Random Number. Show all posts
14 December 2009
12 December 2009
PHP Random Number Generator
This is a very simple php random number generator script.
Creating a random number takes two commands; srand and rand. srand is a preparation command for rand. It helps rand create a truely random number, rand itself creates the random number.
The $from variable is the lowest number possible, and $to is the highest number possible. Simple edit the two variables to suit your requirements.
<?php
$from = 0;
$to = 100;
srand ((double) microtime( )*1000000);
$random_number = rand($from, $to);
echo "$random_number";
?>
Creating a random number takes two commands; srand and rand. srand is a preparation command for rand. It helps rand create a truely random number, rand itself creates the random number.
The $from variable is the lowest number possible, and $to is the highest number possible. Simple edit the two variables to suit your requirements.
<?php
$from = 0;
$to = 100;
srand ((double) microtime( )*1000000);
$random_number = rand($from, $to);
echo "$random_number";
?>
Labels:
PHP Random Number,
PHP Scripts
Subscribe to:
Posts (Atom)