def r8_uniform_01(): #*****************************************************************************80 # ## R8_UNIFORM_01 returns a uniform random real number in [0,1]. # # Discussion: # # This procedure returns a random floating point number from a uniform # distribution over (0,1), not including the endpoint values, using the # current random number generator. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 May 2013 # # Author: # # Original Pascal version by Pierre L'Ecuyer, Serge Cote. # MATLAB version by John Burkardt. # # Reference: # # Pierre LEcuyer, Serge Cote, # Implementing a Random Number Package with Splitting Facilities, # ACM Transactions on Mathematical Software, # Volume 17, Number 1, March 1991, pages 98-111. # # Parameters: # # Output, real R8_UNIFORM_01, a uniform random value in [0,1]. # from i4_uniform import i4_uniform from initialize import initialize from initialized_get import initialized_get # # Check whether the package must be initialized. # if (not initialized_get()): print '' print 'R8_UNIFORM_01 - Note:' print ' Initializing RNGLIB package.' initialize() # # Get a random positive integer. # i = i4_uniform() # # Scale it to a random real in [0,1]. # value = i * 4.656613057E-10 return value
def r8_uniform_01 ( ): #*****************************************************************************80 # ## R8_UNIFORM_01 returns a uniform random real number in [0,1]. # # Discussion: # # This procedure returns a random floating point number from a uniform # distribution over (0,1), not including the endpoint values, using the # current random number generator. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 May 2013 # # Author: # # Original Pascal version by Pierre L'Ecuyer, Serge Cote. # MATLAB version by John Burkardt. # # Reference: # # Pierre LEcuyer, Serge Cote, # Implementing a Random Number Package with Splitting Facilities, # ACM Transactions on Mathematical Software, # Volume 17, Number 1, March 1991, pages 98-111. # # Parameters: # # Output, real R8_UNIFORM_01, a uniform random value in [0,1]. # from i4_uniform import i4_uniform from initialize import initialize from initialized_get import initialized_get # # Check whether the package must be initialized. # if ( not initialized_get ( ) ): print '' print 'R8_UNIFORM_01 - Note:' print ' Initializing RNGLIB package.' initialize ( ) # # Get a random positive integer. # i = i4_uniform ( ) # # Scale it to a random real in [0,1]. # value = i * 4.656613057E-10 return value
def rnglib_test01(): #*****************************************************************************80 # ## RNGLIB_TEST01 calls I4_UNIFORM 10 times, just to show how it is done. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 27 May 2013 # # Author: # # John Burkardt # from cgn_set import cgn_set from i4_uniform import i4_uniform from initialize import initialize print '' print 'RNGLIB_TEST01' print ' I4_UNIFORM ( ) returns a random positive integer' print ' using the current generator.' # # Initialize the package. # print '' print ' INITIALIZE initializes the random number generator.' print ' It only needs to be called once before using the package.' initialize() # # Set the current generator index to #1. # g = 1 cgn_set(g) print '' print ' Current generator index = %d' % (g) # # Now call I4_UNIFORM(). # print '' print ' I I4_UNIFORM ( )' print '' for i in range(1, 11): j = i4_uniform() print ' %2d %12d' % (i, j)