Sage Modeling and Simulation Library

Highpoint.Sage.Randoms Namespace

Classes


  Class Description
Public class GlobalRandomServer
Class GlobalRandomServer is a singleton RandomServer that exists and can be obtained from anywhere in a process space. See RandomServer for details.
Public class MersenneTwisterFast
This is a port of Takuji Nishimura and Makoto Matsumoto's famous Mersenne Twister Pseudorandom number generator. It was ported to C# by Peter Bosch for Highpoint Software Systems, LLC's Sage® product. See the following, but be aware that the RandomServer architecture is independent of the PRNG being used, and is the property of, and copyrighted by, Highpoint Software Systems, LLC.

Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Any feedback is very welcome.

http://www.math.keio.ac.jp/matumoto/emt.html

email: matumoto@math.keio.ac.jp

Updated as of 20160915 : http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

email: m-mat@math.sci.hiroshima-u.ac.jp

Public class RandomServer
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.

Interfaces


  Interface Description
Public interface IRandomChannel
Implemented by an object that can serve random numbers, similarly to the Math.Random() PRNG.