add basic c++ project setup
This commit is contained in:
29
src/lib/utility/random/RandomBinaryFunction.cpp
Normal file
29
src/lib/utility/random/RandomBinaryFunction.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user