Class DotNetRandom
A class implementing IRandom which used for generating pseudo-random numbers using the System.Random class from the .Net framework
Inheritance
Inherited Members
Namespace: RogueSharp.Random
Assembly: RogueSharp.dll
Syntax
public class DotNetRandom : IRandom
Constructors
| Improve this Doc View SourceDotNetRandom()
Constructs a new pseudo-random number generator with a seed based on the number of milliseconds elapsed since the system started
Declaration
public DotNetRandom()
DotNetRandom(Int32)
Constructs a new pseudo-random number generator with the specified seed
Declaration
public DotNetRandom(int seed)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | seed | An integer used to calculate a starting value for the pseudo-random number sequence |
Methods
| Improve this Doc View SourceNext(Int32)
Gets the next pseudo-random integer between 0 and the specified maxValue inclusive
Declaration
public int Next(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxValue | Inclusive maximum result |
Returns
Type | Description |
---|---|
System.Int32 | Returns a pseudo-random integer between 0 and the specified maxValue inclusive |
Next(Int32, Int32)
Gets the next pseudo-random integer between the specified minValue and maxValue inclusive
Declaration
public int Next(int minValue, int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | minValue | Inclusive minimum result |
System.Int32 | maxValue | Inclusive maximum result |
Returns
Type | Description |
---|---|
System.Int32 | Returns a pseudo-random integer between the specified minValue and maxValue inclusive |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown if maxValue equals Int32.MaxValue |
Restore(RandomState)
Restores the state of the pseudo-random number generator based on the specified state parameter
Declaration
public void Restore(RandomState state)
Parameters
Type | Name | Description |
---|---|---|
RandomState | state | The state to restore to, usually obtained from calling the Save method |
Examples
If you generated three random numbers and then called Save to store the state and followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState the Restore method should return the generator back to the state when Save was first called. This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were generated the first time after Save was called.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | RandomState cannot be null |
Save()
Saves the current state of the pseudo-random number generator
Declaration
public RandomState Save()
Returns
Type | Description |
---|---|
RandomState | A RandomState class representing the current state of this pseudo-random number generator |
Examples
If you generated three random numbers and then called Save to store the state and followed that up by generating 10 more numbers before calling Restore with the previously saved RandomState the Restore method should return the generator back to the state when Save was first called. This means that if you went on to generate 10 more numbers they would be the same 10 numbers that were generated the first time after Save was called.