Loadable Function: s = sample (m, n)

Return m unique random integer values from 0..n-1, sorted in ascending order.

Based on a code from Jon Bentley’s "Programming Pearls", see http://netlib.bell-labs.com/cm/cs/pearls/.

Demonstration 1

The following code

 s = sample(4,8)
 % s should contain an increasing sequence of 4 integers from the range 0..7

Produces the following output

s =

   2   4   5   7

Package: miscellaneous