2 #include <gsl/gsl_rng.h>
3 #include <gsl/gsl_histogram2d.h>
8 const gsl_rng_type * T;
11 gsl_histogram2d * h = gsl_histogram2d_alloc (10, 10);
13 gsl_histogram2d_set_ranges_uniform (h,
17 gsl_histogram2d_accumulate (h, 0.3, 0.3, 1);
18 gsl_histogram2d_accumulate (h, 0.8, 0.1, 5);
19 gsl_histogram2d_accumulate (h, 0.7, 0.9, 0.5);
24 r = gsl_rng_alloc (T);
28 gsl_histogram2d_pdf * p
29 = gsl_histogram2d_pdf_alloc (h->nx, h->ny);
31 gsl_histogram2d_pdf_init (p, h);
33 for (i = 0; i < 1000; i++) {
35 double u = gsl_rng_uniform (r);
36 double v = gsl_rng_uniform (r);
38 gsl_histogram2d_pdf_sample (p, u, v, &x, &y);
40 printf ("%g %g\n", x, y);
43 gsl_histogram2d_pdf_free (p);
46 gsl_histogram2d_free (h);