Pegasus InfoCorp: Web site design and web software development company

DRAND48 (3)

drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,

lcong48 - generate uniformly distributed pseudo-random numbers

SYNOPSIS

    #include <stdlib.h>
    double drand48(void);
      double erand48(unsigned short int  xsubi [3]);  
    long int lrand48(void);
      long int nrand48(unsigned short int  xsubi [3]);  
    long int mrand48(void);
      long int jrand48(unsigned short int  xsubi [3]);  
      void srand48(long int  seedval );  
      unsigned short int * seed48(unsigned short int  seed16v [3]);  
      void lcong48(unsigned short int  param [7]);  
    

DESCRIPTION

    These functions generate pseudo-random numbers using the linear congruential algorithm and 48-bit integer arithmetic.

    The drand48() and erand48() functions return non-negative double-precision floating-point values uniformly distributed between [0.0, 1.0).

    The lrand48() and nrand48() functions return non-negative long integers uniformly distributed between 0 and 2^31.

    The mrand48() and jrand48() functions return signed long integers uniformly distributed between -2^31 and 2^31.

    The srand48(), seed48() and lcong48() functions are initialization functions, one of which should be called before using drand48(), lrand48() or mrand49(). The functions erand48(), nrand48() and jrand48() do not require an initialization function to be called first.

    All the functions work by generating a sequence of 48-bit integers, Xi, according to the linear congruential formula:

      Xn+1 = (aXn + c) mod m, where n >= 0

    The parameter m = 2^48, hence 48-bit integer arithmetic is performed. Unless lcong48() is called, a and c are given by:

      a = 0x5DEECE66D c = 0xB

    The value returned by any of the functions drand48(), erand48(), lrand48(), nrand48(), mrand48() or jrand48() is computed by first generating the next 48-bit Xi in the sequence. Then the appropriate number of bits, according to the type of data item to be returned, is copied from the high-order bits of Xi and transformed into the returned value.

    The functions drand48(), lrand48() and mrand48() store the last 48-bit Xi generated in an internal buffer. The functions erand48(), nrand48() and jrand48() require the calling program to provide storage for the successive Xi values in the array argument xsubi. The functions are initialized by placing the initial value of Xi into the array before calling the function for the first time.

    The initializer function srand48() sets the high order 32-bits of Xi to the argument seedval. The low order 16-bits are set to the arbitrary value 0x330E.

    The initializer function seed48() sets the value of Xi to the 48-bit value specified in the array argument seed16v. The previous value of Xi is copied into an internal buffer and a pointer to this buffer is returned by seed48().

    The initialization function lcong48() allows the user to specify initial values for Xi, a and c. Array argument elements param[0-2] specify Xi, param[3-5] specify a, and param[6] specifies c. After lcong48() has been called, a subsequent call to either srand48() or seed48() will restore the standard values of a and c.

CONFORMING TO

    SVID 3

NOTES

    These functions are declared obsolete by SVID 3, which states that rand(3) should be used instead.

SEE ALSO

    - rand (3) - - random (3) - ' " ' " Copyright(c) 1995-1996 Sun Microsystems Inc ' " ' " See the file "license terms" for information on usage and redistribution ' " of this file and for a DISCLAIMER OF ALL WARRANTIES ' " ' " RCS: @(#) $Id: DrawFocHlt 3 v 1 2 1998/09/14 18:22:47 stanton Exp $ ' " ' " The definitions below are for supplemental macros used in Tcl/Tk ' " manual entries ' " ' " AP type name in/out ?indent? ' " Start paragraph describing an argument to a library procedure ' " type is type of argument(int etc ) in/out is either "in" "out" ' " or "in/out" to describe whether procedure reads or modifies arg ' " and indent is equivalent to second arg of IP(shouldn't ever be ' " needed; use AS below instead) ' " ' " AS ?type? ?name? ' " Give maximum sizes of arguments for setting tab stops Type and ' " name are examples of largest possible arguments that will be passed ' " to AP later If args are omitted default tab stops are used ' " ' " BS ' " Start box enclosure From here until next BE everything will be ' " enclosed in one large box ' " ' " BE ' " End of box enclosure ' " ' " CS ' " Begin code excerpt ' " ' " CE ' " End code excerpt ' " ' " VS ?version? ?br? ' " Begin vertical sidebar for use in marking newly-changed parts ' " of man pages The first argument is ignored and used for recording ' " the version when the VS was added so that the sidebars can be ' " found and removed when they reach a certain age If another argument ' " is present then a line break is forced before starting the sidebar ' " ' " VE ' " End of vertical sidebar ' " ' " DS ' " Begin an indented unfilled display ' " ' " DE ' " End of indented unfilled display ' " ' " SO ' " Start of list of standard options for a Tk widget The ' " options follow on successive lines in four columns separated ' " by tabs ' " ' " SE ' " End of list of standard options for a Tk widget ' " ' " OP cmdName dbName dbClass ' " Start of description of a specific option cmdName gives the ' " option's name as specified in the class command dbName gives ' " the option's name in the option database and dbClass gives ' " the option's class in the option database ' " ' " UL arg1 arg2 ' " Print arg1 underlined then print arg2 normally ' " ' " RCS: @(#) $Id: man macros v 1 2 1998/09/14 18:39:54 stanton Exp $ ' " ' " # Set up traps and other miscellaneous stuff for Tcl/Tk man pages t wh -1 3i ^B ^l n( l b ' " # Start an argument description AP !" $4"" TP $4 { !" $2"" TP n()Cu 15