Unique random based on year

24 Views Asked by At

Im developing a app which needs will display one random element from a list every day (list of 366 items).

But I would like this app to display the same item for all users. Also I'd like this calculation to display a different (random) order the next year.

i.e user A: Jan 26th 2017 : item 32 user B: Jan 26th 2017 : item 32

user A: Jan 26th 2017 : item 27 user B: Jan 26th 2017 : item 27

Also I would like the calulation to not show the same item more than once in a given year.

Im not particulary good at maths but I am a programmer, being new to this forum apologies if this question is really basic!

Ordinarly this could be done quite easily with a central repository firing out the item to use with a internet connection but I'd like to make the app work offline.

2

There are 2 best solutions below

1
On

Take the current year as a seed ot a pseudo random number generator and then use the prng to compute a random permutation of $\{1,\ldots,366\}$. Display the item corresponding to the current day of year as index.

2
On

I would suggest to do the following. Number the days of the year 0...365 and number your items the same way. Each day, show the item whose code is $$ \text{last 2 digits of the year } + \text{ day number} \pmod{366} $$ This will order the items in a unique way every year, with a cycle of 100 years. If you want a longer cycle, add 3 last digits of the year.