?? random.3
字號:
.\" SCCSID: @(#)random.3 8.2 1/28/91.TH random 3.SH Namerandom, srandom, initstate, setstate \- better random number generator; routines for changing generators.SH Syntax.nf.B long random().PP.B void srandom(seed).B int seed;.PP.B char *initstate(seed, state, n).B unsigned seed;.B char *state;.B int n;.PP.B char *setstate(state).B char *state;.fi.SH Description.NXR "random subroutine".NXR "srandom subroutine".NXR "initstate subroutine".NXR "setstate subroutine".NXA "rand subroutine (standard C)" "random subroutine".NXR "random number generator"The.PN randomsubroutineuses a non-linear additive feedback random number generator employing adefault table of size 31 long integersto return successive pseudo-randomnumbers in the range from 0 to (2**31)-1. The period of thisrandom number generator isvery large, approximately 16*((2**31)-1)..PPThe.PN random/srandomsubroutineshave (almost) the same calling sequence and initialization properties as.PN rand/srand .The difference is that rand(3)produces a much less random sequence \- in fact, the low dozen bitsgenerated by rand go through a cyclic pattern.All the bits generated by.PN randomare usable. Forexample, \*(lqrandom()&01\*(rq will produce a random binaryvalue..PPUnlike.PN srand ,.PN srandomdoes not return the old seed; the reason for this is that the amount ofstate information used is much more than a single word. (Two otherroutines are provided to deal with restarting/changing randomnumber generators.) Like .MS rand 3 ,however,.PN randomwill by default produce a sequence of numbers that can be duplicatedby calling.PN srandomwith .I 1as the seed..PPThe.PN initstateroutine allows a state array, passed in as an argument, to be initializedfor future use. The size of the state array (in bytes) is used by.PN initstateto decide how sophisticated a random number generator it should use \- themore state, the better the random numbers will be.(Current "optimal" values for the amount of state information are8, 32, 64, 128, and 256 bytes; other amounts will be rounded down tothe nearest known amount. Using less than 8 bytes will cause an error).The seed for the initialization (which specifies a starting point forthe random number sequence, and provides for restarting at the samepoint) is also an argument..PN Initstatereturns a pointer to the previous state information array..PPOnce a state has been initialized, the.PN setstateroutine provides for rapid switching between states.The.PN setstatesubroutine returns a pointer to the previous state array; itsargument state array is used for further random number generationuntil the next call to.PN initstateor.PN setstate ..PPOnce a state array has been initialized, it may be restarted at adifferent point either by calling.PN initstate(with the desired seed, the state array, and its size) or by callingboth.PN setstate(with the state array) and.PN srandom(with the desired seed).The advantage of calling both.PN setstateand.PN srandomis that the size of the state array does not have to be remembered afterit is initialized..PPWith 256 bytes of state information, the period of the random numbergenerator is greater than 2\u\s769\s10\d, which should be sufficient formost purposes..SH DiagnosticsIf.PN initstateis called with less than 8 bytes of state information, or if.PN setstatedetects that the state information has been garbled, errormessages are printed on the standard error output..SH See Alsorand(3)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -