Next Previous Table Of Contents

The PRNG Abstract Base Class

#include <prng/prng.hxx>

Overview

The PRNG abstract base class is designed to aid in the consturction of easy to use pseudo-random number generators. Since it is natural for many pseudo-random number generators to produce several bytes of output at a time, the PRNG base class automatically handles the buffering of this output. Creating a subclass is, therefore, as easy as supplying a method to fill the internal buffer once it is empty.

Protected Variables

_buffer

u8* _buffer;
Points to a high endian byte string representing the output of the pseudo-random number generator.

_bufferSize

int _bufferSize;
This is the number of bytes the internal buffer contains.

_withdrawlPos

int _withdrawlPos;
Position in the byte string pointed to by _buffer that the next byte of output is to be taken from.

Protected Methods

RefillBuffer

virtual void RefillBuffer()=0;
This method needs to be overloaded to write the next _bufferSize bytes of output from the pseudo-random generator, into the memory pointed to by _buffer.

Public Methods

Constructor

PRNG();
Allocates memory for the internal buffer, but does not fill in the first block of data.

Destructor

virtual ~PRNG();
Frees memory allocated to the internal buffer.

NextByte()

u8 NextByte();
Returns the next byte in the stream of bytes produced by the pseudo-random number generator.

NextWord()

u16 NextWord();
Returns the next word in the stream of bytes produced by the pseudo-random number generator, under the assumption that the stream is producing bytes in high endian order.

NextDWord()

u32 NextDWord();
Returns the next dword in the stream of bytes produced by the pseudo-random number generator, under the assumption that the stream is producing bytes in high endian order.

NextQuantum()

void NextQuantum(void* buffer, const int quantumSize);
Writes the next quantumSize bytes of the stream of bytes produced by the pseudo-random number generator into the memory pointed to by buffer.
Next Previous Table Of Contents