├── LICENSE ├── README.md ├── chemicalreactio.c ├── manto carlo.png ├── montecarlo.cpp ├── pokertext.c └── pseudorandom.c /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |

Monte Carlo Pi Estimation

3 |

The Monte Carlo Pi Estimation is a simple program that uses the Monte Carlo method to estimate the value of pi. The program generates a large number of random points and determines the number of points that fall within a circle inscribed in a square. The ratio of the number of points within the circle to the total number of points generated is used to estimate the value of pi.

4 |

System Requirements

5 | 10 |

Installation and Setup

11 |
    12 |
  1. Download and install a C++ compiler on your system.
  2. 13 |
  3. Download the graphics.h library and install it on your system.
  4. 14 |
  5. Download the Monte Carlo Pi Estimation program file (montecarlo.cpp) and save it to a directory of your choice.
  6. 15 |
  7. Compile the program using the following command:
    gcc -pi montecarlo.cpp -lstdc++ -lgraph
  8. 16 |
  9. On Windows, run the compiled executable file (pi.exe) from the command prompt or double-click on it to run it.
  10. 17 |
  11. On Linux, run the compiled executable file (pi.out) from the terminal using the following command:
    ./pi.out
  12. 18 |
19 |

Usage

20 |

After running the program, you will be prompted to enter the number of iterations to perform for the pi estimation. Enter a positive integer value and press Enter.

21 |

The program will display a circle inscribed in a square on the screen, with the center of the circle at (300, 300) and a radius of 200. The program will generate random points within the square and plot them on the screen. Points that fall within the circle will be colored green, while points that fall outside the circle will be colored red.

22 |

After all the points have been generated and plotted, the program will calculate the estimated value of pi based on the ratio of the number of points within the circle to the total number of points generated. The estimated value of pi will be displayed on the screen.

23 | 24 | 25 | 26 | 27 |

Four-Digit Poker Test

28 |

The Four-Digit Poker Test is a statistical test used to determine if a set of randomly generated numbers is independent or not. The test involves generating a large number of four-digit integers and counting the frequency of certain combinations of digits. The observed frequencies are then compared to the expected frequencies, and a chi-squared test is performed to determine if the differences between the observed and expected frequencies are significant.

29 |

How to Use

30 |

To use the Four-Digit Poker Test, follow these steps:

31 |
    32 |
  1. Compile and run the program on your computer. The program requires the user to input the number of numbers generated, as well as the observed frequencies of the following combinations of digits:
  2. 33 | 40 |
  3. After the user inputs the observed frequencies, the program calculates the expected frequencies based on the probabilities of each combination of digits occurring.
  4. 41 |
  5. The program then performs a chi-squared test on the observed and expected frequencies to determine if the generated random numbers are independent or not. If the calculated chi-squared value is less than or equal to the tabulated value for chi-squared, then the numbers are considered independent. Otherwise, they are considered dependent.
  6. 42 |
43 | 44 |

Interpreting Results

45 |

If the program determines that the generated random numbers are independent, this means that the numbers are truly random and do not depend on any previous numbers generated. If the numbers are dependent, this means that there is some pattern or correlation between the generated numbers, indicating that they are not truly random.

46 |

It is important to note that the Four-Digit Poker Test is not foolproof and can only detect certain types of non-randomness. In addition, the test may produce false positives or false negatives, depending on the quality of the random number generator used and the sample size.

47 | 48 |

References

49 | 53 | 54 | 55 | 56 | 57 |

Chemical Reaction Simulation User Manual

58 |

This program simulates the chemical reaction between two reactants (C1 and C2) to produce a product (C3).

59 | less 60 | Copy code 61 |

Program Inputs

62 | 71 | 72 |

Program Outputs

73 |

The program outputs the concentration of C1, C2, and C3 at each time increment, as well as a text file ("lab01.txt") containing the same data.

74 | 75 |

Graphing the Data

76 |

To graph the data, open the "lab01.txt" file in a spreadsheet program (such as Microsoft Excel or Google Sheets) and plot the concentration of each species over time.

77 | 78 | 79 | -------------------------------------------------------------------------------- /chemicalreactio.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int i=0; 7 | float c1[1000],c2[1000],c3[1000]; 8 | float k1=0.025,k2=0.01;//k1 and k2 are constant 9 | c1[0]=30,c2[0]=15,c3[0]=0; 10 | float delta=0.001; //small increment of time 11 | float t=0.0, time=100; 12 | FILE *fp; 13 | fp=fopen("lab01.txt","w"); 14 | 15 | printf("\nC1 C2 C3"); 16 | while(t<=time) 17 | { 18 | printf("\n%f %f %f",c1[i],c2[i],c3[i]); 19 | c1[i+1]=c1[i]+(k2*c3[i]-k1*c1[i]*c2[i])*delta; 20 | c2[i+1]=c2[i]+(k2*c3[i]-k1*c1[i]*c2[i])*delta; 21 | c3[i+1]=c3[i]+(2.0*k1*c1[i]*c2[i]-2.0*k2*c3[i])*delta; 22 | fprintf(fp,"\n%f %f %f",c1[i],c2[i],c3[i]); 23 | i=i+1; 24 | t=t+delta; 25 | } 26 | fclose(fp); 27 | printf("Reaction Simulated"); 28 | } -------------------------------------------------------------------------------- /manto carlo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dyells07/Simulation-Modeling/8ff512a228b4db9aca56ad33e1cf9f783439dbd1/manto carlo.png -------------------------------------------------------------------------------- /montecarlo.cpp: -------------------------------------------------------------------------------- 1 | include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | using namespace std; 8 | void generate_random_points(double &x,double &y){ 9 | x= (double)rand()/RAND_MAX*2-1; 10 | y= (double) rand()/RAND_MAX *2-1; 11 | 12 | } 13 | 14 | int main(){ 15 | int gd=DETECT,gm; 16 | int i,circlepoints=0,squarepoints=0,itetration; 17 | double x,y; 18 | cout<<"Enter number of itetration"; 19 | cin>>itetration; 20 | initgraph(&gd,&gm,NULL); 21 | srand(time(0)); 22 | 23 | circle(300,300,200); 24 | rectangle(100,100,500,500); 25 | 26 | for (i=0;i 3 | //#include 4 | int main() 5 | { 6 | int x0,x1,x2,a,c,m; /*xo=seed, x1=next random number (but for arithmetic, x1 is the 7 | 2nd seed & x2 is next random number,a=constant multiplier, c=increment, m=modulus */ 8 | int i,n,num, method; 9 | int array[20]; //to store the random numbers generated 10 | printf("Choose the method:\n"); 11 | printf("\n1.Linear congruential Method"); 12 | printf("\n2.Arithmetic congruential Method\n"); 13 | scanf("%d",&method); 14 | switch(method) 15 | { 16 | case 1: 17 | printf("\nEnter the seed value x0: "); 18 | scanf("%d",&x0); 19 | printf("\nEnter the modulus m: "); 20 | scanf("%d",&m); 21 | printf("\nHow many random numbers you want to generate: "); 22 | scanf("%d",&n); 23 | printf("\nWhich method you want to perform"); 24 | printf("\n1.Mixed congruential"); 25 | printf("\n2.Additive congruential"); 26 | printf("\n3.Multiplicative congurential\n"); 27 | scanf("\n%d",&num); 28 | switch(num) 29 | { 30 | 31 | case 1: 32 | printf("\nEnter the constant multiplier a: "); 33 | scanf("%d",&a); 34 | 35 | printf("\nEnter the increment c: "); 36 | scanf("%d",&c); 37 | 38 | if(c!=0) 39 | { 40 | for(i=1;i<=n;i++) // loop to generate random numbers 41 | { 42 | x1=(a*x0+c) %m; 43 | array[i]=x1; 44 | x0=x1; 45 | } 46 | 47 | printf("\nThe generated random numbers are: "); 48 | for(i=1;i<=n;i++) 49 | { 50 | printf("\nX%d=%d",i,array[i]); 51 | printf("\t"); 52 | } 53 | } 54 | else 55 | printf("for mixed congruential value of c cannot be zero");break; 56 | case 2: 57 | printf("\nEnter the increment c: "); 58 | scanf("%d",&c); 59 | for(i=1;i<=n;i++) 60 | { 61 | x1=(1*x0+c) %m; 62 | array[i]=x1; 63 | x0=x1; 64 | } 65 | 66 | printf("\nThe generated random numbers are: "); 67 | for(i=1;i<=n;i++) 68 | { 69 | printf("\nX%d=%d",i,array[i]); 70 | printf("\t");break; 71 | } 72 | 73 | case 3: 74 | printf("\nEnter the constant multiplier a: "); 75 | scanf("%d",&a); 76 | 77 | for(i=1;i<=n;i++) 78 | { 79 | x1=(a*x0) %m; 80 | array[i]=x1; 81 | x0=x1; 82 | } 83 | 84 | printf("\nThe generated random numbers are: "); 85 | for(i=1;i<=n;i++) 86 | { 87 | printf("\nX%d=%d",i,array[i]); 88 | printf("\t"); 89 | } 90 | case 4: 91 | printf("Enter the seed value x1: "); 92 | scanf("%d",&x1); 93 | 94 | for(i=1;i<=n;i++) 95 | { 96 | x1=(a*x0) %m; 97 | array[i]=x1; 98 | x0=x1; 99 | } 100 | 101 | printf("\nThe generated random numbers are: "); 102 | for(i=1;i<=n;i++) 103 | { 104 | printf("\nX%d=%d",i,array[i]); 105 | printf("\t"); 106 | }break; 107 | default : 108 | printf("Please Enter 1-4"); 109 | } 110 | break; 111 | 112 | case 2: 113 | printf("\nEnter the seed value x0: "); 114 | scanf("%d",&x0); 115 | 116 | 117 | printf("\nEnter the seed value x1: "); 118 | scanf("%d",&x1); 119 | 120 | printf("\nEnter the modulus m: "); 121 | scanf("%d",&m); 122 | 123 | printf("\nHow many random numbers you want to generate: "); 124 | scanf("%d",&n); 125 | 126 | 127 | for(i=1;i<=n;i++) 128 | { 129 | x2=(x0+x1) %m; 130 | array[i]=x2; 131 | x0=x1; 132 | x1=x2; 133 | } 134 | 135 | printf("\nThe generated random numbers are: "); 136 | for(i=1;i<=n;i++) 137 | { 138 | printf("\nX%d=%d",i+1,array[i]); 139 | printf("\t"); 140 | } 141 | break; 142 | default: 143 | printf("Please Enter 1-2"); 144 | //return switch(method); 145 | } 146 | return 0; 147 | getch(); 148 | } --------------------------------------------------------------------------------