#! /usr/bin/env python # def r8vec_uniform_01_sorted2 ( n, seed ): #*****************************************************************************80 # ## R8VEC_UNIFORM_01_SORTED2 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 r8vec_uniform_01 import r8vec_uniform_01 r8vec = np.zeros ( n ) r, seed = r8vec_uniform_01 ( n, seed ) curmax = 1.0 for i in range ( n - 1, -1, -1 ): curmax = curmax * np.exp ( np.log ( r[i] ) / float ( i + 1 ) ) r8vec[i] = curmax return r8vec, seed def r8vec_uniform_01_sorted2_test ( ): #*****************************************************************************80 # ## R8VEC_UNIFORM_01_SORTED2_TEST tests R8VEC_UNIFORM_01_SORTED2_TEST. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 March 2016 # # Author: # # John Burkardt # from r8vec_transpose_print import r8vec_transpose_print print ( '' ) print ( 'R8VEC_UNIFORM_01_SORTED2_TEST:' ) print ( ' R8VEC_UNIFORM_01_SORTED2 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_sorted2 ( n, seed ) r8vec_transpose_print ( n, r8vec, ' R8VEC:' ) # # Terminate. # print ( '' ) print ( 'R8VEC_UNIFORM_01_SORTED2_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) r8vec_uniform_01_sorted2_test ( ) timestamp ( )