Give:
- Stream (end of stream - EOF)
- Function
next()to get the next element in the stream and move the pointer in the stream - Random generator generating floats between 0 and 1 (inclusive) evenly
Conclusion:
- An element that is considered random (evenly distributed) selected
You can select one or two variables.
You are not allowed to use an array / list, but cannot specify a method trying to get all elements out and store them all and then pick.
This is an interview question.
My thinking:
- I use var
curto store the last saved item - So, if I get a new element, I generate a random generator 0 or 1, if it is 0, then
cur = new element; otherwise continue; - EOF, cur
, ? ?
?