logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

memshuffle - make an array be in random order

Author

       Lars Wirzenius (lars.wirzenius@helsinki.fi)

Publib                                        C Programmer's Manual                             MEMSHUFFLE(3pub)

Bugs

       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.

Description

memshuffle  will  move around the elements of an array in a random fashion.  It uses the standard library
       function rand(3) to get the pseudo-random numbers it needs.  The caller must set  a  suitable  seed  with
       srand(3).

Example

       To shuffle an integer array one might do the following.

            int array[4] = { 1, 2, 3, 4 };

            memshuffle(array, sizeof(array[0]), 4);

Name

       memshuffle - make an array be in random order

Return Value

memshuffle returns its first argument.

See Also

publib(3), memrev(3), rand(3), srand(3)

Synopsis

       #include <publib.h>
       void *memshuffle(void *block, size_t elsize, size_t elnum);

See Also