rofl90 Posted July 31, 2008 Share Posted July 31, 2008 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 More sharing options...
GingerRobot Posted July 31, 2008 Share Posted July 31, 2008 I'd do it like this: <?php $array = range(0,999); shuffle($array); $rand = array_slice($array,0,4); print_r($rand); ?> Link to comment https://forums.phpfreaks.com/topic/117544-random-but-different-numbers/#findComment-604568 Share on other sites More sharing options...
rofl90 Posted July 31, 2008 Author Share Posted July 31, 2008 Could you run me through what that does, and what it'll return, I presume a $rand[0, 1,2,3]? Link to comment https://forums.phpfreaks.com/topic/117544-random-but-different-numbers/#findComment-604571 Share on other sites More sharing options...
rhodesa Posted July 31, 2008 Share Posted July 31, 2008 <?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 ?> Link to comment https://forums.phpfreaks.com/topic/117544-random-but-different-numbers/#findComment-604576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.