in reply to Re: Generating 0 .. N Randomly and Efficiently
in thread Generating 0 .. N Randomly and Efficiently

The problem with your approach is that not only the chances of misses rises as you have selected more items — it is not even garanteed to ever finish;

Unless there's a bug in the implementation, the approach will finish. In fact, it's bounded by O(N2). Each iteration will find a new number - if the initial guess hit an already picked number, a scan for an unpicked number is made. And until all numbers have been picked, a scan will find an unpicked number.

Now, the approach won't be fair (due to clustering), and it won't be fast (quadratic vs. linear), and the implementation might contain bugs (and is huge for such a simple problem), the algorithm will finish (the implementation might not).

  • Comment on Re^2: Generating 0 .. N Randomly and Efficiently