Cheng's BB algorithm for generating Beta distribution random values

View versions (1)

Interface

GPL Licence — free for non commercial use. See Licence details.

FUNCTION

generate

FUNCTION

init

FUNCTION

generate

FUNCTION

RandomSample

Parameters

seed
Default value = 0.63245
beta
Default Value = 1
alpha
Default Value = 1

FUNCTION

genReal

Generate the next random number

Interactive Calculator

Result

FUNCTION

genReal

Interactive Calculator

alpha
beta
Result

FUNCTION

init

FUNCTION

sample

This function is a simple wrapper around the randomsample class provided in this module. It uses a static to keep a single instance of this class, so that each call to this function returns a new random number. As a result this function is not necessarily thread safe, in the sense that with identical initial seed, the sequence of random numbers may differ on a multitasking or multi threaded system.

The seed is only set on the first call to this function. Thereafter this parameter is ignored. If you do no want to set the seed, then we suggest you use the system clock the first time you call this function, i.e.

#include <time.h>
...
sample(alpha, beta, time(0) / MERSENNEDIV);

If you require more advance behaviour, we strongly recommend that directly use the underlying class randomsample that is provided with this module.

Parameters

alpha
first shape parameter for the beta distribution
beta
second shape parameter for the beta distribution
seed
sets the initial seed for the random generator. Only used in the first call to this function

Interactive Calculator

alpha
beta
seed
Result