MEMSHUFFLE(3pub) C Programmer's Manual MEMSHUFFLE(3pub)NAME
memshuffle - make an array be in random order
SYNOPSIS
#include <publib.h>
void *memshuffle(void *block, size_t elsize, size_t elnum);
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).
RETURN VALUE
memshuffle returns its first argument.
EXAMPLE
To shuffle an integer array one might do the following.
int array[4] = { 1, 2, 3, 4 };
memshuffle(array, sizeof(array[0]), 4);
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.
SEE ALSO publib(3), memrev(3), rand(3), srand(3)AUTHOR
Lars Wirzenius (lars.wirzenius@helsinki.fi)
Publib C Programmer's Manual MEMSHUFFLE(3pub)
Check Out this Related Man Page
RAND(3) BSD Library Functions Manual RAND(3)NAME
rand, rand_r, srand, sranddev -- bad random number generator
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
int
rand(void);
int
rand_r(unsigned *seed);
void
srand(unsigned seed);
void
sranddev(void);
DESCRIPTION
These interfaces are obsoleted by random(3).
The rand() function computes a sequence of pseudo-random integers in the range of 0 to RAND_MAX (as defined by the header file <stdlib.h>).
The srand() function sets its argument seed as the seed for a new sequence of pseudo-random numbers to be returned by rand(). These
sequences are repeatable by calling srand() with the same seed value.
If no seed value is provided, the functions are automatically seeded with a value of 1.
The sranddev() function initializes a seed, using the random(4) random number device which returns good random numbers, suitable for crypto-
graphic use.
The rand_r() function provides the same functionality as rand(). A pointer to the context value seed must be supplied by the caller.
SEE ALSO random(3), random(4)STANDARDS
The rand() and srand() functions conform to ISO/IEC 9899:1990 (``ISO C90'').
The rand_r() function is as proposed in the POSIX.4a Draft #6 document.
BSD May 25, 1999 BSD
hi
I want to get a rodom integer, but I just get the same integer while using the fuction rand() for the first time. So I wonder wether there is a way in which I can get an unknow random integer.
Thanks in advance (2 Replies)
Hi,
I am having trouble with generating random numbers. can this be done with awk?
So I have a file that looks like this:
23 30
24 40
26 34
So column1 is start and column2 is end. I want to generate 3 random #'s between start and stop:
So the output will look like this:
... (9 Replies)
Hi,
I am trying to read a set of numbers that are in scientific notation into a file so I can do some math on them, but when I display the array contents the numbers aren't the same as the numbers in the file.
Could someone explain why? Thanks.
int main()
{
double fArray;
... (3 Replies)
Hi,
Is there any way I can shuffle the numbers randomly. I have been trying to google and I found lots of 'generator' but is it possible to find the background logic to create randomness?
Thanks, (3 Replies)
Hello,
I think there's an easier way to do this but can't seem to recall but given an array of animals and an initial value is a random index in the array, here it's 3.
3,4,5,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0... inifinite repeat
a quick brute force solution i came up with was two functions, i... (6 Replies)