/* Author: Clare Quarman * Date: July 2003 * Purpose: demonstrate use og GSL random no generator in a c++ program * */ // things i like to use #include #include #include using std::cout; using std::cin; using std::endl; using std::cerr; // GSL thing for random numbers #include gsl_rng * r; // pointer to a global random no generator int main (){ // have to do these things first - they are explained in manual const gsl_rng_type * T; gsl_rng_env_setup(); T = gsl_rng_default; r = gsl_rng_alloc (T); // get a random number from a uniform [0,1) distribution double u = gsl_rng_uniform (r); if (u<0.5){ cout << "heads" << endl; }else{ cout << "tails" << endl; } // at end of program must get rid of memory used by the generator gsl_rng_free (r); return EXIT_SUCCESS; }