shuffle.h

This file exports functions for generating pseudorandom numbers.
Functions
shuffle(arraylength) Randomly rearranges the elements of the given array up to the given length.
shuffle(array2drowscols) Randomly rearranges the elements of the given 2-D array up to the given number of rows and columns.
shuffle(grid) Randomly rearranges the elements of the given grid.
shuffle(str) Randomly rearranges the characters of the given string.
shuffle(vector) Randomly rearranges the elements of the given vector.

Function detail


template <typename T>
void shuffle(T* array, int length);
Randomly rearranges the elements of the given array up to the given length. Precondition: The array pointer points to a valid non-NULL array in memory, and that array contains at least 'length' elements.

Usage:

shuffle(a, len);

template <typename T>
void shuffle(T** array2d, int rows, int cols);
Randomly rearranges the elements of the given 2-D array up to the given number of rows and columns. Precondition: The array pointer points to a valid non-NULL 2-D array in memory, and that array contains at least the given number of rows/columns.

Usage:

shuffle(a2d, rows, cols);

template <typename ValueType>
void shuffle(Grid<ValueType>& grid);
Randomly rearranges the elements of the given grid.

Usage:

shuffle(myGrid);

string shuffle(string str);
Randomly rearranges the characters of the given string, returning the shuffled result.

Usage:

string s2 = shuffle(str);

template <typename ValueType>
void shuffle(Vector<ValueType>& vector);
Randomly rearranges the elements of the given vector.

Usage:

shuffle(myVector);