Skip to content
Snippets Groups Projects
Commit 39605372 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

std: add event support in the include random

parent d5d40b19
No related branches found
No related tags found
1 merge request!220Merge jt
......@@ -2,7 +2,7 @@
 
namespace ext {
 
std::random_device & random_devices::random = getRandom ( );
random_devices::semirandom_device & random_devices::semirandom = getSemirandom ( );
std::random_device & random_devices::random = getRandom ( );
random_devices::semirandom_device & random_devices::semirandom = getSemirandom ( );
 
} /* namespace ext */
......@@ -143,5 +143,36 @@ public:
 
};
 
} /* namespace ext */
class uniform_unsigned_event {
unsigned m_probability;
static constexpr unsigned PROBABILITY_MIN = 0;
static constexpr unsigned PROBABILITY_MAX = 100;
public:
uniform_unsigned_event ( unsigned probability ) : m_probability ( probability ) {
}
template< class Generator >
bool operator ( ) ( Generator & g ) const {
static std::uniform_int_distribution < unsigned > generator ( PROBABILITY_MIN, PROBABILITY_MAX - 1 );
return generator ( g ) < m_probability;
}
};
class uniform_real_event {
double m_probability;
 
static constexpr double PROBABILITY_MIN = 0.;
static constexpr double PROBABILITY_MAX = 1.;
public:
uniform_real_event ( double probability ) : m_probability ( probability ) {
}
template< class Generator >
bool operator ( ) ( Generator & g ) const {
static std::uniform_real_distribution < double > generator ( PROBABILITY_MIN, PROBABILITY_MAX );
return generator ( g ) < m_probability;
}
};
} /* namespace ext */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment