logoalt Hacker News

olooneytoday at 4:07 PM4 repliesview on HN

> so hopefully you can refresh a few times and get a fresh one every time

If you randomly sample from only 60 quotes, then after 10 refreshes there will be a greater than 50% chance of at least one repeat, and by 20 refreshes it's up to 95%. This is an example of the birthday paradox[1].

On the flip side, if someone wants to see all 60 quotes, they will have to refresh the page an average of 281 times, mostly (~80%) seeing quotes they've already seen before. This is an example of the coupon collector's problem[2].

The way to avoid both these problems is to shuffle the quotes into a random order, just once, and remember that order. The first time a user comes to the page, start at a random index in that shuffled list, and from then on, simply move to the next item in the list. Every user will get a unique set of random quotes, but will see no repeats until the list is exhausted, and will be guaranteed to be able to see all available content in just 60 refreshes.

[1]: https://en.wikipedia.org/wiki/Birthday_problem

[2]: https://en.wikipedia.org/wiki/Coupon_collector%27s_problem


Replies

thekaranchawlatoday at 4:58 PM

TIL about the coupon collector problem. Thanks for sharing that link

xandriustoday at 5:00 PM

I'd prefer have a unique and shared quote each day keyed on the day of the year. Then restart when going above N and shuffle.

show 1 reply
dantillbergtoday at 4:36 PM

If the user doesn't know how many unique items there are, they would need to keep refreshing even longer to gauge whether the N they've seen is the full set.

alansabertoday at 4:12 PM

Make sure you fingerprint every user to make sure they're using the right index value /s