Other random results

Back to Random real numbers. Forward to Other random distributions. Up to Contents.

The following routines return true with the given probability

Definitions of routines returning booleans

routine

probability

Boolean()

1/2

Prob<NumericType>(NumericType p)

p

Prob<NumericType>(NumericType m, NumericType n)

m/n

Prob accepts both real and integer types. However, typically the one-argument version (the Bernoulli distribution) would be used with a real argument and the two-argument version would be used with integer arguments. Prob<NumericType>(NumericType p) is false if p <= 0 and true if p >= 1. Prob<NumericType>(NumericType m, NumericType n) returns false if m <= 0 or n < 0 and true if m >= n. The results of Prob are exact. In particular, Prob<double>(x, y) returns true with probability x/y even if x/y cannot be exactly represented as a double (e.g., it underflows to zero).

Equivalences between routines returning booleans

Function

Equivalent

Boolean()

Integer<bool>()

Boolean()

Prob(1, 2)

Boolean()

Prob(0.5)

Prob<RealType>(x)

Float<RealType>() < x

Prob<RealType>(x)

FloatU<RealType>() <= x

Finally, Bits<n>() returns n random bits in a std::bitset<n>.

Back to Random real numbers. Forward to Other random distributions. Up to Contents.

Generated on Thu Dec 31 15:24:29 2009 by  doxygen 1.6.1