A random number generator using a physical entropy source (if available). Falls transparently back on PRNG on errors. More...
Public Member Functions | |
| PhysicalRandomNumberGenerator (EntropySourceType source, string agentName) | |
| Create a physical random number generator. | |
| int | Next (int minValue, int maxValue) |
| Generate random number within a given range [min,max] against the current entropy source. | |
Properties | |
| PlayTrulyRandom | PlayTrulyRandom [get] |
| Gets the current PTR instance. | |
| EntropySourceType | EntropySource [get, set] |
| Gets the current type of random number entropy. | |
| string | AgentName [get] |
| Gets the current type of random number entropy. | |
| int | RetrievedEntropyBits [get, set] |
| Gets or Sets the count of entropy bits that were retrieved. | |
A random number generator using a physical entropy source (if available). Falls transparently back on PRNG on errors.
Definition at line 32 of file PhysicalRandomNumberGenerator.cs.
| NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.PhysicalRandomNumberGenerator | ( | EntropySourceType | source, | |
| string | agentName | |||
| ) |
Create a physical random number generator.
| source | The source of the entropy. | |
| agentName | The name of the agent using the generator (i.e. the name of the game or webservice access code). |
Definition at line 107 of file PhysicalRandomNumberGenerator.cs.
| int NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.Next | ( | int | minValue, | |
| int | maxValue | |||
| ) |
Generate random number within a given range [min,max] against the current entropy source.
| minValue | The inclusive minimum value to be generated. | |
| maxValue | The inclusive maximum value to be generated. maxValue must be greater or equals than minValue. |
Definition at line 131 of file PhysicalRandomNumberGenerator.cs.
00132 { 00133 if (maxValue < minValue) 00134 { 00135 throw new ArgumentException( 00136 "maxValue must be greater or equals than minValue", 00137 "maxValue"); 00138 } 00139 00140 int result = 0; 00141 00142 // Generate based on entropy source type 00143 switch (this.entropySource) 00144 { 00145 // OS based pseudo generator 00146 case EntropySourceType.Pseudo: 00147 // Adjust for exclusive range of .Next 00148 if (maxValue < int.MaxValue) 00149 { 00150 maxValue++; 00151 } 00152 00153 result = this.prng.Next(minValue, maxValue); 00154 this.retrievedEntropyBits += 32; 00155 break; 00156 00157 // PTR webservice 00158 case EntropySourceType.PlayTrulyRandom: 00159 try 00160 { 00161 int retrievedBits; 00162 result = playTrulyRandom.Next(minValue, maxValue, out retrievedBits); 00163 this.retrievedEntropyBits += retrievedBits; 00164 } 00165 catch (Exception) 00166 { 00167 // On error, fall back on pseudo random number generator 00168 this.entropySource = EntropySourceType.Pseudo; 00169 result = this.Next(minValue, maxValue); 00170 } 00171 00172 break; 00173 } 00174 00175 return result; 00176 }
string NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.AgentName [get] |
Gets the current type of random number entropy.
Definition at line 88 of file PhysicalRandomNumberGenerator.cs.
EntropySourceType NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.EntropySource [get, set] |
Gets the current type of random number entropy.
Definition at line 74 of file PhysicalRandomNumberGenerator.cs.
PlayTrulyRandom NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.PlayTrulyRandom [get] |
Gets the current PTR instance.
Definition at line 66 of file PhysicalRandomNumberGenerator.cs.
int NewGamePhysics.PhysicalElements.PhysicalRandomNumberGenerator.RetrievedEntropyBits [get, set] |
Gets or Sets the count of entropy bits that were retrieved.
Definition at line 96 of file PhysicalRandomNumberGenerator.cs.
1.6.2