Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Random wind speed generator with 0.05% possibility of storm with winds 10 mph higher
- //Initialize objects
- #include<iostream>
- #include<iomanip>
- #include<fstream>
- #include<ctime>
- #include<cstdlib>
- double a,b;
- double random(double a, double b);
- double random_gust(double a, double b);
- using namespace std;
- int main()
- {
- //User input for wind range
- cout<<"Please enter range for wind speed"<<endl;
- cin>>a>>b;
- //Seed for random number generator, based on computer clock
- srand(time(NULL));
- //Open data file
- ofstream outfile;
- outfile.open("wind.txt");
- //Write header
- outfile<<"TIME"<<setw(10)<<"SPEED"<<endl;
- //For loop to write normal data
- for(int i=0; i<=3600; i=i + 10)
- {
- //If else for possibility of storm
- if (rand()%1001 <=5)
- {
- //For loop to write storm data
- for(int k=i; k<=i+300; k=k + 10)
- {
- outfile<<k<<setw(10)<<setprecision(4)<<random_gust(a, b)<<" ***** "<<endl;
- }
- i=i+300;
- }
- else
- {
- outfile<<i<<setw(10)<<setprecision(4)<<random(a, b)<<endl;
- }
- }
- outfile.close();
- }
- //Module for normal wind speeds
- double random(double a, double b)
- {
- return ((double)rand()/RAND_MAX)*(b-a) + a;
- }
- //Module for storm wind speeds
- double random_gust(double a, double b)
- {
- return ((double)rand()/RAND_MAX)*((b+10)-(a+10)) + (a+10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement