GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MEMSHUFFLE(3) C Programmer's Manual MEMSHUFFLE(3)

memshuffle - make an array be in random order

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

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).

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.

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

Lars Wirzenius (lars.wirzenius@helsinki.fi)
C Programmer's Manual Publib

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.