### Reliability Issue

I am trying to write a program that simulates the configuration shown below, using a component reliability of 0.8 for components 1 and 2, and 0.95 for components 3 and 4. I want to print the estimate of the reliability, using 5,000 simulations. (The analytical reliability of
this system is 0.9649.) This is what I have so far however I'm getting a reliability value of 1 so I think I have gone wrong somewhere. Thanks for any help! :)

Configuration c= component
 ``` C1-----C2 a----| |---b C3-----C4 ```

 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````#include #include #include #include #include #include using namespace std; double rand_double(double a, double b) { return ((double)rand()/RAND_MAX)*(b-a) + a; } int main() { double c1,c2,c3, c4; int success = 0; int total = 5000; for(int i = 0; i < total; i++) { c1 = rand_double(0,1); c2 = rand_double(0,1); c3 = rand_double(0,1); c4 = rand_double (0,1); if( c1 < 0.8 || c2 < 0.8 || c3 < 0.95 || c4 < 0.95) { success++; } } cout << "By simulation, reliability is " << (double)success/total << endl; system("PAUSE"); return 0; } ``````
Last edited on
Try seeding the random number generator with srand(time(NULL)) once at the start of your program.
Thanks for the tip! I tried doing that but the program is not compiling! :( Ive never used the srand(time(NULL)) command so I may be missing something.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041`` `````` #include #include #include #include #include #include using namespace std; double rand_double(double a, double b) { return ((double)rand()/RAND_MAX)*(b-a) + a; } int main() { srand(time(NULL)) double c1,c2,c3, c4; int success = 0; int total = 5000; for(int i = 0; i < total; i++) { c1 = rand_double(0,1); c2 = rand_double(0,1); c3 = rand_double(0,1); c4 = rand_double (0,1); if( c1 < 0.8 || c2 < 0.8 || c3 < 0.95 || c4 < 0.95) { success++; } } cout << "By simulation, reliability is " << (double)success/total << endl; system("PAUSE"); return 0; } ``````
When there are errors, you should provide them so we can figure out the problem.
Sorry! It says " 17:16: error :'time' was not declared in this scope"
Topic archived. No new replies allowed.