I'm looking for an algorithm, pseudocode or any langauge, to generate random numbers with the following characteristics:
integer values in the range 0-n
lower values much more likely to happen than higher values,
eg prob of 0 is n/(n(n-1)), prob of n is 1/(n(n-1)) - linear relationship between value and probablility
but the exact relationship isn't important - could be exponential, square etc
speed/efficiency is important - don't want to use expensive functions like exp, log sqrt etc
I'd be grateful for any suggestions, pointers, or links.
Thanks
James
(In case anyone wants to know, short version: this is for picking requests from a FIFO queue - the items should be picked randomly, but the earlier requests should have a higher probablility of being picked)