37 lines
611 B
C++
37 lines
611 B
C++
// Implements the CRandom class
|
|
// This class implements the Lehmer Random Number Generator
|
|
|
|
#include "Random.h"
|
|
#include <time.h>
|
|
|
|
CRandom::CRandom()
|
|
{
|
|
m_state = (uint32_t)time(nullptr);
|
|
}
|
|
|
|
CRandom::CRandom(uint32_t state_value)
|
|
{
|
|
m_state = state_value;
|
|
}
|
|
|
|
uint32_t CRandom::randomizer(uint32_t val)
|
|
{
|
|
return ((uint64_t)val * 279470273UL) % 4294967291UL;
|
|
}
|
|
|
|
uint32_t CRandom::next()
|
|
{
|
|
m_state = randomizer(m_state);
|
|
return m_state;
|
|
}
|
|
|
|
void CRandom::set_state(uint32_t state_value)
|
|
{
|
|
m_state = state_value == 0 ? 1 : state_value;
|
|
}
|
|
|
|
uint32_t CRandom::get_state()
|
|
{
|
|
return m_state;
|
|
}
|