Generate random number from stream with equal probability
Filed under Groupon
The question
Given a stream of numbers with O(1) space and no ability to store previously seen numbers, generate a random number from the stream with equal probability.
No write-up yet. Related questions below have one.
Related Groupon questions
Collected from public candidate posts and coding forums. Updated Nov 2026.