jburkardt_allocatable_c( 純C 動態配置記憶體+產生AB兩數之間均勻分布的隨機變數函數[i4_uniform_ab]+顯示目前時間函數[timestamp] ) – [c_src001]
jburkardt_allocatable_c( 純C 動態配置記憶體+產生AB兩數之間均勻分布的隨機變數函數[i4_uniform_ab]+顯示目前時間函數[timestamp] ) – [c_src001]
資料來源:https://people.sc.fsu.edu/~jburkardt/
線上執行:http://www.tutorialspoint.com/compile_c_online.php [ 自己下 gcc -o main *.c -lm ]
# include <stdlib.h> int main ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ MAIN is the main program for ALLOCATABLE. Discussion: ALLOCATABLE demonstrates how a C function can call another function, Licensing: This code is distributed under the GNU LGPL license. Modified: 25 February 2014 Author: John Burkardt timestamp ( ); test01 ( &n, &a ); printf ( “\n” ); return 0; void test01 ( int *n, int **a ) /******************************************************************************/ TEST01 allocates and assigns the array. Licensing: This code is distributed under the GNU LGPL license. Modified: 25 February 2014 Author: John Burkardt seed = 123456789; ( *a ) = ( int * ) malloc ( ( *n ) * sizeof ( int ) ); for ( i = 0; i < *n; i++ ) return; int i4_uniform_ab ( int a, int b, int *seed ) /******************************************************************************/ I4_UNIFORM_AB returns a scaled pseudorandom I4 between A and B. Discussion: The pseudorandom number should be uniformly distributed Licensing: This code is distributed under the GNU LGPL license. Modified: 24 May 2012 Author: John Burkardt Reference: Paul Bratley, Bennett Fox, Linus Schrage, Bennett Fox, Pierre L’Ecuyer, Peter Lewis, Allen Goodman, James Miller, Parameters: Input, int A, B, the limits of the interval. Input/output, int *SEED, the “seed” value, which should NOT be 0. Output, int I4_UNIFORM_AB, a number between A and B. if ( *seed == 0 ) k = *seed / 127773; *seed = 16807 * ( *seed – k * 127773 ) – k * 2836; if ( *seed < 0 ) r = ( float ) ( *seed ) * 4.656612875E-10; return value; void timestamp ( ) /******************************************************************************/ TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 31 May 2001 09:45:54 AM Licensing: This code is distributed under the GNU LGPL license. Modified: 24 September 2003 Author: John Burkardt Parameters: None static char time_buffer[TIME_SIZE]; now = time ( NULL ); strftime ( time_buffer, TIME_SIZE, “%d %B %Y %I:%M:%S %p”, tm ); printf ( “%s\n”, time_buffer ); return; |