def latin_random ( dim_num, point_num, seed ): #*****************************************************************************80 # ## LATIN_RANDOM returns points in a Latin Random square. # # Discussion: # # In each spatial dimension, there will be exactly one # point whose coordinate value lies between consecutive # values in the list: # # ( 0, 1, 2, ..., point_num ) / point_num # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 13 November 2014 # # Author: # # John Burkardt # # Parameters: # # Input, integer DIM_NUM, the spatial dimension. # # Input, integer POINT_NUM, the number of points. # # Input/output, integer SEED, a seed for the random # number generator. # # Output, real X(DIM_NUM,POINT_NUM), the points. # from perm_uniform import perm_uniform from r8mat_uniform_01 import r8mat_uniform_01 # # Pick DIM_NUM * POINT_NUM random numbers between 0 and 1. # x, seed = r8mat_uniform_01 ( dim_num, point_num, seed ) # # For spatial dimension I, # pick a random permutation of 1 to POINT_NUM, # force the corresponding I-th components of X to lie in the # interval ( PERM(J)-1, PERM(J) ) / POINT_NUM. # for i in range ( 0, dim_num ): perm, seed = perm_uniform ( point_num, seed ) for j in range ( 0, point_num ): x[i,j] = ( perm[j] + x[i,j] ) / point_num return x, seed
def i4vec_permute_test ( ): #*****************************************************************************80 # ## I4VEC_PERMUTE_TEST tests I4VEC_PERMUTE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 25 October 2014 # # Author: # # John Burkardt # from i4vec_print import i4vec_print from i4vec_uniform_ab import i4vec_uniform_ab from perm_uniform import perm_uniform n = 12 print '' print 'I4VEC_PERMUTE_TEST' print ' I4VEC_PERMUTE reorders an I4VEC' print ' according to a given permutation.' b = 0 c = n seed = 123456789 a, seed = i4vec_uniform_ab ( n, b, c, seed ) i4vec_print ( n, a, ' A[*], before rearrangement:' ) p, seed = perm_uniform ( n, seed ) i4vec_print ( n, p, ' Permutation vector P[*]:' ) a = i4vec_permute ( n, p, a ) i4vec_print ( n, a, ' A[P[*]]:' ) print '' print 'I4VEC_PERMUTE_TEST:' print ' Normal end of execution.' return