Random permutations


Functions

static unsigned myrand_n (unsigned n)
 Return a random unsigned integer between 0 and n-1.
static void myswap (unsigned i, unsigned j, unsigned *restrict table)
 Swap i and j in table.
static void identity_permutation (unsigned n, unsigned *restrict table)
 Store the identity permutation of n elements into table.
static void rand_permutation (unsigned n, unsigned *restrict table)
 Store a random permutation of n elements into table.
static void builtin_rng_permutation (builtin_rng_state_t *restrict state, unsigned n, unsigned *restrict table)
 Store a random permutation of n elements into table.


Function Documentation

static void builtin_rng_permutation ( builtin_rng_state_t *restrict  state,
unsigned  n,
unsigned *restrict  table 
) [inline, static]

Store a random permutation of n elements into table.

Uses builtin_rng.

Definition at line 347 of file types.c.

References builtin_rng_n(), identity_permutation(), and myswap().

Referenced by next_permutation().

static void identity_permutation ( unsigned  n,
unsigned *restrict  table 
) [inline, static]

Store the identity permutation of n elements into table.

Definition at line 325 of file types.c.

Referenced by builtin_rng_permutation(), next_permutation(), and rand_permutation().

static unsigned myrand_n ( unsigned  n  )  [inline, static]

Return a random unsigned integer between 0 and n-1.

Uses the random number generator in the C library.

Definition at line 309 of file types.c.

Referenced by rand_permutation().

static void myswap ( unsigned  i,
unsigned  j,
unsigned *restrict  table 
) [inline, static]

Swap i and j in table.

Definition at line 316 of file types.c.

Referenced by builtin_rng_permutation(), and rand_permutation().

static void rand_permutation ( unsigned  n,
unsigned *restrict  table 
) [inline, static]

Store a random permutation of n elements into table.

Uses the random number generator from the C library.

Definition at line 335 of file types.c.

References identity_permutation(), myrand_n(), and myswap().

Referenced by next_permutation().