Unix/Linux Go Back    

Plan 9 - man page for rand (plan9 section 2)

Linux & Unix Commands - Search Man Pages
Man Page or Keyword Search:   man
Select Man Page Set:       apropos Keyword Search (sections above)

RAND(2) 										  RAND(2)

       rand, lrand, frand, nrand, lnrand, srand - random number generator

       #include <u.h>
       #include <libc.h>

       int    rand(void)

       long   lrand(void)

       double frand(void)

       int    nrand(int val)

       long   lnrand(long val)

       void   srand(long seed)

       Rand returns a uniform pseudo-random number x, 0<=x<215.

       Lrand returns a uniform long x, 0<=x<231.

       Frand  returns a uniform double x, 0.0<=x<1.0, This function calls lrand twice to generate
       a number with as many as 62 significant bits of mantissa.

       Nrand returns a uniform integer x, 0<=x<val.  Lnrand is the same, but returns a long.

       The algorithm is additive feedback with:

	      x[n] = (x[n-273] + x[n-607]) mod 2^31

       giving a period of 2^30 x (2^607 - 1).

       The generators are initialized by calling srand with whatever you like  as  argument.   To
       get a different starting value each time,


       will work as long as it is not called more often than once per second.  Calling


       will initialize the generators to their starting state.

       There is no rand in Alef.


Unix & Linux Commands & Man Pages : ©2000 - 2018 Unix and Linux Forums

All times are GMT -4. The time now is 07:43 PM.