Jump to content

having 6 random numbers output different numbers


cloudll

Recommended Posts

You can avoid a loop with

$my_numbers = array_rand(array_flip(range(1, 100)), 6);
or the cleaner

$rand_nums = range(1, 100);
shuffle($rand_nums);
$my_numbers = array_slice($rand_nums, 0, 6);
There won't be much of a difference if you're only getting 6 numbers out of 100, but if you tried more like 6/7 or 90/100 then you'd notice a big one.

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.