I have to select k distinct numbers from an array such that probability of a number getting selected is more if it is at the end of the array (probability increases linearly). I'm thinking of assigning probability to each number as
current_position_of_number_in_array/(n*(n+1)/2)
where n is the size of the given array. Then generate a random number between 0 and 1 and selecting the number in array which falls into that range. This will work fine if I have to select non-distinct numbers, but in case I have to select distinct numbers, this won't be efficient if size of k is of the order of n.(assuming I'm using some kind of hash-set to discard repeated numbers)
Are there better algorithms to select k distinct numbers which are of better big-oh complexity ?
I finally ended up using weighted reservoir sampling with uniformly increasing weights.
Here is a detailed paper: http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
Implementation in Java: http://utopia.duth.gr/~pefraimi/projects/WRS/