Click to See Complete Forum and Search --> : random number generator


sheerin
February 10th, 2005, 05:26 AM
Im doing an examination question bank. I would like the bank/system to randomly
pick questions for the exam paper. Anyone that has knowledge with random number generation, please help me out. Thanx

blueday54555
February 10th, 2005, 05:50 AM
this generates a random number between 0 an 1000

<?
$test = rand(0,1000);
echo $test;
?>

bigBA
February 11th, 2005, 11:48 AM
well, that would return the same number sequence every time.

so use srand() before.


srand(uniqueid(time()));
... rand()
(or something like that)

blueday54555
February 11th, 2005, 12:13 PM
the usage of srand is e.g.

srand ((double)microtime()*1000000);

the time is a comon used value for this issues

bigBA
February 11th, 2005, 12:15 PM
yeah.. sorry. mixed that up with session handling... :) :thumb:

First Base
February 13th, 2005, 02:39 AM
here's a code that randomly generates 12 numbers:

<?php
$num1=rand(1111,9999);
$num2=rand(1111,9999);
$num3=rand(1111,9999);
echo"$num1$num2$num3";
?>

-firstbase