There are applications in which it is useful to have a list of N random integers drawn from some integral range in sorted order. (Formally, we desire a sorted selection without replacement in which each selection occurs equiprobably.) For example, when a university sends evaluation forms to a random selection of former students of some professor who is being evaluated for promotion, it is very handy for an administrative assistant to be able to generate, for example, 100 random numbers in sorted order in the range 1 ... 263 (where we have addresses for 263 of the professor's former students). The output is required to be sorted because the list of names isn't numbered.
Reference: Jon Bentley, Programming Pearls, Chapter 11, citing Donald Knuth, Seminumerical Algorithms, §3.4.2, Algorithm S.
WARNING: One reference I consulted indicated that Internet Explorer does not randomize the random number generator, so that the same list will be generated (for the same input parameters) each time the browser is restarted. Either a) use Netscape, Mozilla, Opera, Konqueror, etc., or b) generate a few lists of different sizes from different ranges before generating the actual list you want.
NOTE: If you have the opposite problem -- you want a random ordering of all the integers in some range -- see Randomly Scrambled Lists of Numbers
Copyright © 2000, 2004 Jonathan Mohr