Fulqrum Publishing Home   |   Register   |   Today Posts   |   Members   |   UserCP   |   Calendar   |   Search   |   FAQ

Go Back   Official Fulqrum Publishing forum > Fulqrum Publishing > IL-2 Sturmovik: Cliffs of Dover > FMB, Mission & Campaign builder Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2011, 10:32 AM
Octocat Octocat is offline
Approved Member
 
Join Date: Dec 2011
Posts: 22
Default

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.
Reply With Quote
  #2  
Old 12-08-2011, 10:53 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Quote:
Originally Posted by Octocat View Post
More concise and economical way to generate random numbers:

code removed by author
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.
Reply With Quote
  #3  
Old 12-08-2011, 11:24 AM
Octocat Octocat is offline
Approved Member
 
Join Date: Dec 2011
Posts: 22
Default

Here the main idea: do not create an object of Random anew for each use. One would be enough.
Reply With Quote
  #4  
Old 12-08-2011, 01:16 PM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

Quote:
Originally Posted by Octocat View Post
Here the main idea: do not create an object of Random anew for each use. One would be enough.
So are you saying that the NextInt routine would be better if the highlighted line were used?

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.
Reply With Quote
  #5  
Old 12-08-2011, 01:37 PM
Octocat Octocat is offline
Approved Member
 
Join Date: Dec 2011
Posts: 22
Default

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.
Reply With Quote
  #6  
Old 12-08-2011, 01:51 PM
Octocat Octocat is offline
Approved Member
 
Join Date: Dec 2011
Posts: 22
Default

Quote:
The random method certainly uses less resources...
Random in not the method, but class.

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);
Reply With Quote
  #7  
Old 12-08-2011, 02:23 PM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:49 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.