Jump to content

Random but different numbers


rofl90

Recommended Posts

What I want to do is:

 

      $flagIdRand_Correct = rand(0, 999); //update to amount of flags correct answer

        $flagIdRandWrong_a = rand(0, 999); //incorrect answer 1

        $flagIdRandWrong_b = rand(0, 999); //incorrect answer 2

        $flagIdRandWrong_c = rand(0, 999); //incorrect answer 3

 

4 random numbers, they all need to be different..hwo would i do this

Link to comment
https://forums.phpfreaks.com/topic/117544-random-but-different-numbers/
Share on other sites

<?php
$rands = range(0,999); //Makes an array from 0 to 999
shuffle($rands); //Randomizes the array
$flagIdRand_Correct = rands[0]; //update to amount of flags correct answer
$flagIdRandWrong_a = rands[1]; //incorrect answer 1
$flagIdRandWrong_b = rands[2]; //incorrect answer 2
$flagIdRandWrong_c = rands[3]; //incorrect answer 3
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.