Test random number GSL function. More...
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <libgen.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <utils.h>
Go to the source code of this file.
Defines | |
#define | _GNU_SOURCE |
GNU extensions. | |
Functions | |
void | show_usage (char *pgm) |
C prototypes. | |
int | main (int argc, char **argv) |
Main program. |
Test random number GSL function.
Definition in file testrandomu.c.
#define _GNU_SOURCE |
GNU extensions.
Definition at line 59 of file testrandomu.c.
int main | ( | int | argc, | |
char ** | argv | |||
) |
Main program.
[in] | argc | Number of command-line arguments. |
[in] | argv | Vector of command-line argument strings. |
Definition at line 102 of file testrandomu.c.
References banner(), and show_usage().
00103 { 00111 unsigned long int random_num, i; 00112 00113 const gsl_rng_type *T; 00114 gsl_rng *rng; 00115 00116 /* Print BEGIN banner */ 00117 (void) banner(basename(argv[0]), "1.0", "BEGIN"); 00118 00119 /* Get command-line arguments and set appropriate variables */ 00120 for (i=1; i<argc; i++) { 00121 if ( !strcmp(argv[i], "-h") ) { 00122 (void) show_usage(basename(argv[0])); 00123 (void) banner(basename(argv[0]), "OK", "END"); 00124 return 0; 00125 } 00126 else { 00127 (void) fprintf(stderr, "%s:: Wrong arg %s.\n\n", basename(argv[0]), argv[i]); 00128 (void) show_usage(basename(argv[0])); 00129 (void) banner(basename(argv[0]), "ABORT", "END"); 00130 (void) abort(); 00131 } 00132 } 00133 00134 /* Initialize random number generator */ 00135 T = gsl_rng_default; 00136 rng = gsl_rng_alloc(T); 00137 (void) gsl_rng_set(rng, time(NULL)); 00138 00139 for (i=0; i<1000000; i++) { 00140 random_num = gsl_rng_uniform_int(rng, 100); 00141 (void) fprintf(stdout,"%ld\n",random_num); 00142 } 00143 00144 (void) gsl_rng_free(rng); 00145 00146 /* Print END banner */ 00147 (void) banner(basename(argv[0]), "OK", "END"); 00148 00149 return 0; 00150 }
void show_usage | ( | char * | pgm | ) |
C prototypes.
Local Subroutines.
Show usage for program command-line arguments.
[in] | pgm | Program name. |
Definition at line 156 of file testrandomu.c.