is it possible to customize mt_rand to a function which gives me a line of numbers without repeats.
For example mt_rand(1,5)
should give me 4,2,3,1,5 or something like that.
is it possible to customize mt_rand to a function which gives me a line of numbers without repeats.
For example mt_rand(1,5)
should give me 4,2,3,1,5 or something like that.
This achieves what you ask in your question:
$results = range(1, 5);
shuffle($results);
For more complex needs, you can use Faker.
For instance the randomElements() method, here picking 5 non-duplicate numbers in the 1-10 range:
$faker = \Faker\Factory::create();
$results = $faker->randomElements(range(1, 10), 5, false);
(though, this can also be done with regular PHP easily:)
$pool = range(1, 10);
shuffle($pool);
$results = array_slice($pool, 0, 5);