This is a quickie that came out of my computer programming work adapted as a puzzle.
I propose to stand in front of you with a bag of balls. I will hand you the balls one at a time. You have no idea how many balls my bag contains. I will also provide you with a magic device such that when its button is pushed, it provides you with a random number between 0 and 1. You may use this as often as you like.
You must hold on to exactly one ball at a time. When I hand you a ball, you must either throw it away immediately or else retain it and throw away the ball that you were previously holding. After you have either retained or thrown away the last ball, your goal is for there to be an exactly equal chance that you are currently holding each of the balls that I have handed you.
It may help to provide a similar problem to demonstrate how you might use the magical device to accomplish something similar. Suppose that I told you in advance that there were ten balls. You could then use the device to generate your random number and multiply that number by 10. This would give you a random number between 0 and 10 uniformly distributed over that range. You could then designate all numbers up to 1 as pointing to the first ball, numbers greater than 1 up to 2 as the second ball, etc. Your strategy would then be to throw away balls until handed the ball corresponding to your number and retaining that one from then on. With this strategy, you would retain each of the balls with an exactly 10% chance.
This method can’t be directly adapted to the puzzle because you wouldn’t know what multiple to use before the first draw because you don’t know how many balls will be present, so you’ll need another strategy.