Skip to content

Random Number Generation

Chris3606 edited this page Oct 20, 2018 · 8 revisions

GoRogue relies on the excellent Troschuetz.Random library for fast and easy random number generation. The currentdocumentation can be found here.

Table of Contents

Code Examples

Code examples in this section show only code in the Main function. The code provided assumes that the following "using" statements are at the top of the code file:

using GoRogue.Random;

Basics of Random Number Generation

Generating random numbers in a default manner is fairly easy, since a default RNG is provided.

The Default RNG

A public (and settable) property is provided that allows the RNG that is considered to be. It also has a default value, (details BELOW) This provides a convenient, succinct way to generate random numbers:

// Gets a random integer between 1 and 6, inclusive
int random1 = SingletonRandom.DefaultRNG.Next(1, 6);
// When only a max is specified, the minimum is implicitly 0.
// Thus, here we get a random number between 0 and 6, inclusive.
int random2 = SingletonRandom.DefaultRNG.Next(6);