mercredi 25 janvier 2017

Generate random number that changes every month

I need to generate a random number within a given range. The number must be different for every new month of the year, and it should not be the same (although theoretically it is possible) as the number generated the year before for that given month.

I was thinking of using the php rand($min, $max) function in conjunction with date("w"), I am struggling with the part where I need to get different results for every year.

To illustrate what I mean, check this:

$numbers = range(1, 100); //our random array
echo $numbers[date("w")]; //date("w") returns number of week

There are 2 problems here: 1) it is not really random, 2) the number will be the same every year and 3) it does not reflect the whole size of the array as date("w") returns a number between 1 and 52.

Do you think this is accomplishable in pure PHP? Or do I need to make a cronjob for this?

Thank you for any help.




Aucun commentaire:

Enregistrer un commentaire