// Taken from https://www.electro-tech-online.com/threads/ultra-fast-pseudorandom-number-generator-for-8-bit.124249/
//X ABC Algorithm Random Number Generator for 8-Bit Devices:
//This is a small PRNG, experimentally verified to have at least a 50 million byte period
//by generating 50 million bytes and observing that there were no overapping sequences and repeats.
//This generator passes serial correlation, entropy , Monte Carlo Pi value, arithmetic mean,
//And many other statistical tests. This generator may have a period of up to 2^32, but this has
//not been verified.
//
// By XORing 3 bytes into the a,b, and c registers, you can add in entropy from
//an external source easily.
//
//This generator is free to use, but is not suitable for cryptography due to its short period(by //cryptographic standards) and simple construction. No attempt was made to make this generator
// suitable for cryptographic use.
//
//Due to the use of a constant counter, the generator should be resistant to latching up.
//A significant performance gain is had in that the x variable is only ever incremented.
//
//Only 4 bytes of ram are needed for the internal state, and generating a byte requires 3 XORs , //2 ADDs, one bit shift right , and one increment. Difficult or slow operations like multiply, etc
//were avoided for maximum speed on ultra low power devices.
voidCAX25RX::initRand()//Can also be used to seed the rng with more entropy during use.
{
m_a=(m_a^m_c^m_x);
m_b=(m_b+m_a);
m_c=(m_c+(m_b>>1)^m_a);
}
uint8_tCAX25RX::rand()
{
m_x++;//x is incremented every round and is not affected by any other variable
m_a=(m_a^m_c^m_x);//note the mix of addition and XOR
m_b=(m_b+m_a);//And the use of very few instructions
m_c=(m_c+(m_b>>1)^m_a);//the right shift is to ensure that high-order bits from b can affect
returnuint8_t(m_c);//low order bits of other variables