Posted by CyberDog on 06/24/05 17:52
Andrew @ Rockface wrote:
> I think the shuffle is the best way, unless you've got a massive amount of
> questions :)
>
> $questions_in_database = 10;
> $questions = range(0,$questions_in_database);
> shuffle($questions);
> for ($c = 0; $c < 5; $c++) {
> echo "RANDOM NUMBER =".$questions[$c]."<br>";
> }
>
> If you want to use the other method:
>
> $questions_in_database = 5;
> $questions = array();
> for ($c = 0; $c < 5; $c++) {
> $rnd = mt_rand(0,$questions_in_database);
> if (! in_array($rnd, $questions)) {
> $questions[] = $rnd;
> }
> }
> echo "<pre>";print_r($questions);echo "</pre>";
You helped a lot, thank you! :)
[Back to original message]
|