Uniform (0,1) Random Variate



Uniform(0,1) Random Variate
The probability density function for a uniform(0,1) distributed random variable X, f(x), is:
f(x) =
0for x ≤ 0
1 for 0 < x < 1
0for x ≥ 1.

Because uniform random variates are frequently used to generate random variates with different probability distributions and many algorithms are available to generate a uniform random variate; the place holders, Uniform_Random_Variate() and Uniform_32_Bits_Random_Variate() are used for the uniform distributed random variate. Any other function which uses a uniform random variate calls either Uniform_0_1_Random_Variate() or Uniform_32_Bits_Random_Variate(), which calls the algorithm to generate a uniform random variate. The function, Init_Uniform_Random_Variate(), must be called prior to calling either Uniform_Random_Variate() or Uniform_32_Bits_Random_Variate().

The uniform random number generator based on the Mersenne Twister is considered to be the best uniform generator available. The best way to obtain a copy of such a function is to search for "Mersenne Twister" using your favorite search engine. The uniform random number generator given below is based on rand() in stdlib.

Function List

  • void Init_32_Uniform_0_1_Random_Variate( void (*init_rv)(unsigned long seed), unsigned long seed, double (*r_generator)(void), unsigned long (*i_generator)(void) )

    This function sets the Uniform_Random_Variate() random number generator to that specified by the argument "r_generator" and the Uniform_32_Bits_Random_Variate() random number generator to that specified by the argument "i_generator" so that later calls to Uniform_Random_Variate() will call the function given in "r_generator" and later calls to Uniform_32_Bits_Random_Variate() will call the function given in "i_generator". The function specified in "init_rv" is called using the "seed" to initialize the random number generator. Currently, the functions (see below) in stdlib_uniform_0_1_variate.c: Init_Stdlib_Uniform_0_1_Variate(), Stdlib_Uniform_0_1_Variate(), and Stdlib_Uniform_32_Bits_Variate() can be used as arguments. But a version based on the Mersenne Twister is recommended.

  • double Uniform_0_1_Random_Variate( void )

    This function calls the uniform(0,1) generator specified in the argument "r_generator" of Init_32_Uniform_0_1_Random_Variate to return a uniform(0,1) random variate.
     
  • unsigned long Uniform_32_Bits_Random_Variate( void )

    This function calls the uniform(0,232) generator specified in the argument "i_generator" of Init_32_Uniform_0_1_Random_Variate to return an integer valued uniform random variate in the range 0 to 232 - 1.

  • void Init_Stdlib_Uniform_0_1_Variate( unsigned long seed )

    This function simply calls the stdlib function srand() with the valued specified in seed.

  • double Stdlib_Uniform_0_1_Variate( void )

    This function simply returns a call to the stdlib function rand() divided by
    RAND_MAX + 1.

  • unsigned long Stdlib_Uniform_32_Bits_Variate( void )

    This function simply returns calls to the stdlib function (int) rand() to return a function of type unsigned long.

Source Code

C source code is available for these routines: