Monday, April 7, 2008

Solution to Programming Quiz: Populating stream with unique random numbers

The generator and the consuming code is as below:


Reader is requested to provide comment if it feels that the above can be made more efficient and has better algorithm than what is shown here.




Programming Quiz: Populating stream with unique random numbers

Create a class which populates a stream with k unique random numbers between 0 to max - 1 in an efficient ( No Space vs Speed tradeoff ) manner.

Below are variables and should be the input to the algorithm:
stream: Stream
k: int
max: int