cnet's Application Programming Interface
- NAME
- CNET_newrand, CNET_nextrand - generate pseudo-random numbers
- SYNOPSIS
#include <cnet.h>
CnetRandom CNET_newrand(unsigned int seed);
long CNET_nextrand(CnetRandom stream);
- DESCRIPTION
-
Each node may employ multiple independent pseudo-random sequences.
CNET_newrand returns an opaque stream identifier for
a new random sequence,
and
CNET_nextrand accepts the stream identifier to generate the next
independent random number in that sequence on [0..MAXLONG].
A typical use is:
CnetRandom stream1, stream2;
int firstlink, alternatelink;
stream1 = CNET_newrand(123);
stream2 = CNET_newrand(456);
.....
firstlink = CNET_nextrand(stream1) % nodeinfo.nlinks + 1;
do {
alternatelink = CNET_nextrand(stream2) % nodeinfo.nlinks + 1;
} while (alternatelink == firstlink);
The independent random sequences may be generated at different rates
without interfering with one another.
If the -S command-line option is provided,
it will be used to seed each random number stream,
and the argument to CNET_newrand() will be ignored.
cnet employs the Mersenne Twister (MT19937) random number generator.
- RETURN VALUE
-
CNET_newrand returns a new random stream identifier.
CNET_nextrand returns the next long integer in the
random sequence on [0..MAXLONG].
SEE ALSO
CNET_srand and
CNET_rand
The Mersenne Twister home page.
|
cnet v3.3.4, written by Chris.McDonald@uwa.edu.au
Last modified: Tue Mar 1 7:43AM 2016