Home
Main website
Display Sidebar
Hide Ads
Recent Changes
View Source:
rand(3)
Edit
PageHistory
Diff
Info
LikePages
RAND !!!RAND NAME SYNOPSIS DESCRIPTION RETURN VALUE NOTES CONFORMING TO SEE ALSO ---- !!NAME rand, srand - random number generator. !!SYNOPSIS __#include __ ''seed''__); __ !!DESCRIPTION The __rand()__ function returns a pseudo-random integer between 0 and __RAND_MAX__. The __srand()__ function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by __rand()__. These sequences are repeatable by calling __srand()__ with the same seed value. If no seed value is provided, the __rand()__ function is automatically seeded with a value of 1. !!RETURN VALUE The __rand()__ function returns a value between 0 and RAND_MAX. The __srand()__ returns no value. !!NOTES The versions of __rand()__ and __srand()__ in the Linux C Library use the same random number generator as __random()__ and __srandom()__, so the lower-order bits should be as random as the higher-order bits. However, on older __rand()__ implementations, the lower-order bits are much less random than the higher-order bits. In ''Numerical Recipes in C: The Art of Scientific Computing'' (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling; New York: Cambridge University Press, 1992 (2nd ed., p. 277)), the following comments are made: j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); and never by anything resembling j=1+(rand() % 10); (which uses lower-order bits). Random-number generation is a complex topic. The ''Numerical Recipes in C'' book (see reference above) provides an excellent discussion of practical random-number generation issues in Chapter 7 (Random Numbers). For a more theoretical discussion which also covers many practical issues in depth, please see Chapter 3 (Random Numbers) in Donald E. Knuth's ''The Art of Computer Programming'', volume 2 (Seminumerical Algorithms), 2nd ed.; Reading, Massachusetts: Addison-Wesley Publishing Company, 1981. !!CONFORMING TO SVID 3, BSD 4.3, ISO 9899 !!SEE ALSO random(3), srandom(3), initstate(3), setstate(3) ----
10 pages link to
rand(3)
:
drand48(3)
srandom(3)
perldelta(1)
Man3r
crypto(3)
initstate(3)
setstate(3)
strfry(3)
random(3)
RandomNumberGenerator
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.