#! /usr/bin/env python # def r8vec_uniform_01_sorted1 ( n, seed ): #*****************************************************************************80 # ## R8VEC_UNIFORM_01_SORTED1 returns a sorted real random vector in [0,1]. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 March 2016 # # Author: # # John Burkardt # # Reference: # # Jon Bentley, James Saxe, # Generating sorted lists of random numbers, # ACM Transactions on Mathematical Software, # Volume 6, Number 3, September 1980, pages 359-364. # # Parameters: # # Input, integer N, the number of values to generate. # # Input, integer SEED, the integer "seed" used to generate # the output random number. SEED should not be 0. # # Output, real R8VEC(N), a real vector of random values # in ascending order. # # Output, integer SEED, the updated seed. # import numpy as np from r8_uniform_01 import r8_uniform_01 r8vec = np.zeros ( n ) s = 0.0 for i in range ( 0, n + 1 ): r, seed = r8_uniform_01 ( seed ) s = s - np.log ( r ) if ( i == n ): break r8vec[i] = s for i in range ( 0, n ): r8vec[i] = r8vec[i] / s return r8vec, seed def r8vec_uniform_01_sorted1_test ( ): #*****************************************************************************80 # ## R8VEC_UNIFORM_01_SORTED1_TEST tests R8VEC_UNIFORM_01_SORTED1_TEST, # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 March 2016 # # Author: # # John Burkardt # import platform from r8vec_transpose_print import r8vec_transpose_print print ( '' ) print ( 'R8VEC_UNIFORM_01_SORTED1_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' R8VEC_UNIFORM_01_SORTED1 generates a vector of N random' ) print ( ' values in ascending sorted order.' ) print ( '' ) print ( ' Generate several examples:' ) print ( '' ) n = 5 seed = 123456789 for i in range ( 0, 10 ): r8vec, seed = r8vec_uniform_01_sorted1 ( n, seed ) r8vec_transpose_print ( n, r8vec, ' R8VEC:' ) # # Terminate. # print ( '' ) print ( 'R8VEC_UNIFORM_01_SORTED1_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8vec_uniform_01_sorted1_test ( ) timestamp ( )