mercredi 21 octobre 2015

Php Unique Random Number with exception

I built a random number like this:

$numbers = range(0, 14);

$currentWeek = $date->format('W');

shuffle($numbers);

foreach($users as $user) {

    $uniqueRand = (array_pop($numbers)+$currentWeek) % 52 + 1;
}

So that gives each user in my db a random number between today to 52 and then start from 1 again if the ranged is not totally filled so to say.

Now I have another column with numbers in my db and I want that the user will not randomly get the same number here.

So like this:

Users     |     Number 1      |       Number 2
______________________________________________
Jack      |        10        |         5

and not like this:

Users     |     Number 1      |       Number 2
______________________________________________
Jack      |        10        |         10




Aucun commentaire:

Enregistrer un commentaire