MythTV  master
Typedefs | Functions
MythRandomStd Namespace Reference

Typedefs

using MythRandomGenerator_32 = std::mt19937
 
using MythRandomGenerator_64 = std::mt19937_64
 

Functions

uint32_t MythRandom ()
 generate 32 random bits More...
 
uint64_t MythRandom64 ()
 generate 64 random bits More...
 
uint32_t MythRandom (uint32_t min, uint32_t max)
 generate a uniformly distributed random uint32_t in the closed interval [min, max]. More...
 
int MythRandomInt (int min, int max)
 generate a uniformly distributed random signed int in the closed interval [min, max]. More...
 
bool rand_bool (uint32_t chance=2)
 return a random bool with P(true) = 1/chance More...
 

Typedef Documentation

◆ MythRandomGenerator_32

using MythRandomStd::MythRandomGenerator_32 = typedef std::mt19937

Definition at line 14 of file mythrandom.h.

◆ MythRandomGenerator_64

using MythRandomStd::MythRandomGenerator_64 = typedef std::mt19937_64

Definition at line 15 of file mythrandom.h.

Function Documentation

◆ MythRandom() [1/2]

uint32_t MythRandomStd::MythRandom ( )
inline

generate 32 random bits

Definition at line 20 of file mythrandom.h.

Referenced by rand_bool().

◆ MythRandom64()

uint64_t MythRandomStd::MythRandom64 ( )
inline

generate 64 random bits

Definition at line 31 of file mythrandom.h.

◆ MythRandom() [2/2]

uint32_t MythRandomStd::MythRandom ( uint32_t  min,
uint32_t  max 
)
inline

generate a uniformly distributed random uint32_t in the closed interval [min, max].

The behavior is undefined if $min > max$.

An alternate name would be MythRandomU32.

Definition at line 45 of file mythrandom.h.

◆ MythRandomInt()

int MythRandomStd::MythRandomInt ( int  min,
int  max 
)
inline

generate a uniformly distributed random signed int in the closed interval [min, max].

The behavior is undefined if $min > max$.

Definition at line 58 of file mythrandom.h.

◆ rand_bool()

bool MythRandomStd::rand_bool ( uint32_t  chance = 2)
inline

return a random bool with P(true) = 1/chance

An input less than 2 always returns true:

  • for chance = 1: range is [0, 0], i.e. always 0
  • for chance = 0: range is [0, -1], unsigned integer underflow! (or just undefined behavior if signed)

This is a Bernoulli distribution with $p = 1 / chance$.

Definition at line 75 of file mythrandom.h.