Class KnownSeriesRandom
A class implementing IRandom which cycles through a specified series of integers each time the Next random number is asked for.
Inheritance
Inherited Members
Namespace: RogueSharp.Random
Assembly: RogueSharp.dll
Syntax
public class KnownSeriesRandom : IRandom
Remarks
This class is normally used for unit tests and not production code.
Constructors
| Improve this Doc View SourceKnownSeriesRandom(Int32[])
Constructs a new integer generator with the specified series of integers in an array. When the Next method is called on this generator it will return the first integer in the series, followed by the next integer and so on until it reaches the end of the array. If the Next method is called once it is at the end of the array, it will start back over at the beginning.
Declaration
public KnownSeriesRandom(params int[] series)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | series | A known series of integers that will be returned in order from this generator |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown on null series |
Methods
| Improve this Doc View SourceNext(Int32)
Return the first integer in the series that was specified when this generator was constructed, followed by the next integer and so on until it reaches the end of the array. If the Next method is called once it is at the end of the array, it will start back over at the beginning.
Declaration
public int Next(int maxValue)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | maxValue | Inclusive maximum result |
Returns
Type | Description |
---|---|
System.Int32 | The next integer in the series specified upon construction of this class |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when the Next integer in the series for this generator is not between 0 and the specified maxValue inclusive |
Next(Int32, Int32)
Return the first integer in the series that was specified when this generator was constructed, followed by the next integer and so on until it reaches the end of the array. If the Next method is called once it is at the end of the array, it will start back over at the beginning.
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 | The next integer in the series specified upon construction of this class |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when the Next integer in the series for this generator is not between the specified minValue and maxValue inclusive |
Restore(RandomState)
Restores the state of the 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 | Thrown on null RandomState |
Save()
Saves the current state of the number generator
Declaration
public RandomState Save()
Returns
Type | Description |
---|---|
RandomState | A RandomState class representing the current state of this 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.