Make an array be in random order
#include <publib.h> void *memshuffle(void *block, size_t elsize, size_t elnum);
memshuffle returns its first argument.
To shuffle an integer array one might do the following.
int array[4] = { 1, 2, 3, 4 }; memshuffle(array, sizeof(array[0]), 4);
On many systems rand(3) is not of very good quality. However, it is the only random number generator that can be assumed to exist. Making it possible for the caller to provide an alternate source of random numbers (e.g., via a function pointer) is perhaps too more trouble than its worth. A better way would be for everyone to fix their rand's.
Lars Wirzenius ([email protected])