Sample from the Beta distribution
Build two sample programs:
- build a histogram of sample counts (10 bins)
- stream of samples
$ mkdir build
$ cd build
$ cmake ..
$ make
Run the sample programs:
$ ./sample_hist 1.0 2.0
1821 1679 1602 1274 1117 890 756 475 278 108
$ ./sample_stream 1.0 2.0
0.130430
0.622695
0.473631
...
<Ctrl-C>
-
Include the header
libbeta.h
into your program -
Set parameters
a
andb
for the Beta distribution to sample from -
Call
beta_sample_BA(a, b)
to get a sample
Inspired by James McCaffrey's Blog
[1] R. C. H. Cheng, Generating Beta Variates with Nonintegral Shape Parameters, Communications of the ACM, Vol. 21, Issue 4, pp. 317-322, 1978.