Sage Modeling and Simulation Library

RandomServer Class

The random server serves channels from which fixed sequences of pseudo-random numbers can be drawn. Each channel is serviced by a Mersenne Twister Random Number Generator. The server can be created with or without a default buffer size, and thereafter, each channel can be created with or without a specified buffer size. If a channel's buffer size is not specified, it utilizes a buffer of the default size.

Buffering Scheme:

Each channel, if it has a non-zero buffer size, utilizes a double buffering scheme where the PRNG is filling the back buffer in a producer thread while the model is using the front buffer in its consumer thread. Due to the Windows threading model, this results in better PRNG performance even when the consumer thread is processor-bound, at least over the longer-haul (more than a few tens of consumptions.) It will really shine when there is more than one processor in the system. You can play around with buffer size, and the effect probably varies somewhat with RNG consumption rate, but you might start with a number somewhere around 100. This will be the subject of study, some day...

Note: If using buffering, the model/consumer must call Dispose() on the Random Channel once it is finished with that Random Channel.

If there is a zero buffer size specified, the consumer always goes straight to the PRNG to get its next value. This option may be slightly faster in cases where the machine is running threads that are higher than user priority, and usually starving the system, but in our tests, it ran at about half the speed. In this case, there is no explicit need to call Dispose() on the Random Channel.

Coming Enhancements:

Two, mainly. First, using a single thread per RandomServer, rather than per RandomChannel. And second, making it so that you don't have to call Dispose() any more.

Namespace:  Highpoint.Sage.Randoms
Assembly:  Sage4 (in Sage4.dll)


public class RandomServer

Inheritance Hierarchy