man(1) Manual page archive


     RAND(3)                                                   RAND(3)

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

     SYNOPSIS
          int rand()

          long lrand()

          double frand()

          int nrand(val)
          int val;

          srand(seed)
          int seed;

     DESCRIPTION
          Rand uses a linear feedback random number generator to
          return uniform pseudo-random numbers x, 0<=x<2^15, with
          period about 2^32.

          Lrand returns a uniform long x, 0<=x<2^31, with period about
          2^48.

          Frand returns a uniform double x, 0.0<=x<1.0, always a mul-
          tiple of 2^-31.

          Nrand returns a uniform integer x, 0<=x<val.

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

               srand((int)time((long *)0));

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

     BUGS
          Rand and lrand are quite machine-dependent.  Although frand
          and nrand are more portable, they appear in few versions of
          Unix.