30 lines
637 B
C++
30 lines
637 B
C++
#include "RandomBinaryFunction.h"
|
|
|
|
#include "utilityRandom.h"
|
|
|
|
RandomBinaryFunction::RandomBinaryFunction(float resolution_s, float stateChangeProbability)
|
|
: m_resolution_s(resolution_s)
|
|
, m_stateChangeProbability(stateChangeProbability)
|
|
, m_passedTime_s(0.0f)
|
|
, m_value(utility::getRandomBool())
|
|
{
|
|
}
|
|
|
|
void RandomBinaryFunction::update(float deltaTime_s)
|
|
{
|
|
m_passedTime_s += deltaTime_s;
|
|
while (m_passedTime_s >= m_resolution_s)
|
|
{
|
|
m_passedTime_s -= m_resolution_s;
|
|
if (utility::getRandomFloat() >= m_stateChangeProbability)
|
|
{
|
|
m_value = !m_value;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool RandomBinaryFunction::getValue() const
|
|
{
|
|
return m_value;
|
|
}
|