![]() |
|
|
|
#1
|
|||
|
|||
|
More concise and economical way to generate random numbers:
Code:
internal ISectionFile RandomiseMission()
{
var random = new Random(Environment.TickCount);
...
value = random.Next(minBreezeActivity, maxBreezeActivity).ToString();
...
value = random.Next(minThermalActivity, maxThermalActivity).ToString();
...
}
Last edited by Octocat; 12-08-2011 at 10:40 AM. |
|
#2
|
|||
|
|||
|
It's a moot point. The random method certainly uses less resources & therefore is "more efficient", but many argue about the "randomness" of the numbers generated. The Cryptography system method uses more resources, but provides a "better" (more unpredictable) random number set. Of course, to get true randon numbers you would have to seed the generator with something truely random such as cosmic radiation or background noise.
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash. Get the latest COD Team Fusion patch info HERE Last edited by salmo; 10-18-2012 at 10:32 AM. |
|
#3
|
|||
|
|||
|
Here the main idea: do not create an object of Random anew for each use. One would be enough.
|
|
#4
|
|||
|
|||
|
Quote:
code removed by author
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash. Get the latest COD Team Fusion patch info HERE Last edited by salmo; 10-18-2012 at 10:32 AM. |
|
#5
|
|||
|
|||
|
No, code "return Random(result).Next(min, max);" is syntactic error for C# compiler, because keyword new required.
I saying, you can remove NextInt function completely. Then create single instance of Random class in the RandomizeWeather function, and then use it as many times as you like, as in my example above. |
|
#6
|
|||
|
|||
|
Quote:
Line below creates instance of Random class, and assigns the value to variable named random. var random = new Random(Environment.TickCount); Now, we can call method "Next" any number of times: int randomNumber = random.Next(min, max); |
|
#7
|
|||
|
|||
|
Thankyou Octocat. I known how random.next works, but I chose to go with the RNGCryptoServiceProvider rather than the Random class because I feel it gives me "better" random numbers. Anyone using the script is welcome to replace the NextInt routine with the random class as suggested.
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash. Get the latest COD Team Fusion patch info HERE |
![]() |
|
|