24 time_t t0 = std::time(0);
25 gmp_randseed_ui(r, t0);
29 mpfr_prec_t prec = 240; mpfr_init2(z, prec);
30 std::cout <<
"Sample from the unit normal distribution at precision "
33 for (
int k = 0; k < 10; ++k) {
34 norm(z, r, MPFR_RNDN);
35 mpfr_out_str(stdout, 10, 0, z, MPFR_RNDN); std::cout <<
"\n";
40 mpfr_prec_t prec = 20; mpfr_set_prec(z, prec);
41 std::cout <<
"Sample ranges from the normal distribution at precision "
45 for (
int k = 0; k < 10; ++k) {
48 std::cout <<
"[" << mpfr_get_d(z, MPFR_RNDD) <<
",";
50 std::cout << mpfr_get_d(z, MPFR_RNDU) <<
"] -> ";
52 mpfr_out_str(stdout, 10, 0, z, MPFR_RNDN); std::cout <<
"\n";
57 mpfr_clear(z); mpfr_free_cache(); gmp_randclear(r);
60 std::cerr <<
"Need MPFR version 3.0 or later to run MPFRExample\n";
Handling random numbers in MPFR.
The normal distribution for MPFR.