Class Generator
Framework-wide random number generator. If you would like to always generate the same results when using the framework, set the Seed property of this class to a fixed value.
Inheritance
Namespace: ISynergy.Framework.Mathematics.Random
Assembly: ISynergy.Framework.Mathematics.dll
Syntax
public static class Generator : object
Remarks
By setting Seed to a given value, it is possible to adjust how random numbers are generated within the framework. Preferably, this property should be adjusted before other computations.
If the Seed is set to a value that is less than or equal to zero, all generators will start with the same fixed seed, even among multiple threads. If set to any other value, the generators in other threads will start with fixed, but different, seeds.
Properties
View SourceHasBeenAccessed
Gets a value indicating whether the random number generator has been used during the execution of any past code. This can be useful to determine whether a method or learning algorithm is fully deterministic or not. Note that it is also possible for a method to be non-deterministic even if it uses the random number generator if it use multiple threads.
Declaration
public static bool HasBeenAccessed { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LastUpdateTicks
Gets the timestamp for when the global random generator was last changed (i.e. after setting Seed).
Declaration
public static long LastUpdateTicks { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Random
Gets a reference to the random number generator used internally by the ISynergy.Framework.Mathematics.NET classes and methods. Objects retrieved from this property should not be shared across threads. Instead, call this property from each thread you would like to use a random generator for.
Declaration
public static Random Random { get; }
Property Value
Type | Description |
---|---|
System.Random |
Seed
Sets a random seed for the framework's main internal number generator . Preferably, this method should be called before other computations. If set to a value less than or equal to zero, all generators will start with the same fixed seed, even among multiple threads. If set to any other value, the generators in other threads will start with fixed, but different, seeds.
Declaration
public static int? Seed { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Int32> |
Remarks
Adjusting the global generator seed causes the calling thread to sleep for 100ms so new threads spawned in a short time span after the call can be properly initialized with the new random seeds. In order to better control the random behavior of different algorithms, please consider specifying random generators directly using appropriate interfaces for these algorithms in case they are available.
If you do not need to change the seed number for threads other than the current, you can adjust the random seed for the current thread using ThreadSeed instead. Setting ThreadSeed should not introduce delays.
ThreadLastUpdateTicks
Gets the timestamp for when the thread random generator was last changed (i.e. after creating the first random generator in this thread context or by setting ThreadSeed).
Declaration
public static long ThreadLastUpdateTicks { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
ThreadSeed
Gets or sets the seed for the current thread. Changing this seed will not impact other threads or generators that have already been created from this thread.
Declaration
public static int? ThreadSeed { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Int32> |