1

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 Answers2

3

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.

  • Great solution, for coding folks who would like know how to implment this there is a little guide here http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html – RedCrusador May 15 '17 at 15:13
2

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.

gt6989b
  • 54,422
  • Good solution but would we not be seeing the same order of quotes each year, but just the next quote along in the series? – RedCrusador May 15 '17 at 15:23
  • @RedCrusador yes. it seemed to me the OP was not interested in random ordering per se, but any ordering, as is common in programming problems... – gt6989b May 15 '17 at 15:42