⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 galileo.c

📁 Simulation Modeling,Discrete Event Simulation,Statistical Analysis of Simulation Models
💻 C
字号:
/* -------------------------------------------------------------------------  * A Monte Carlo simulation of Galileo's three dice experiment.  *  * Name              : galileo.c  * Author            : Steve Park & Dave Geyer  * Language          : ANSI C * Latest Revision   : 9-11-98 * -------------------------------------------------------------------------  */#include <stdio.h>#include "rng.h"#define N 10000L                          /* number of replications */   long Equilikely(long a, long b)        /* ------------------------------------------------ * generate an Equilikely random variate, use a < b  * ------------------------------------------------ */{  return (a + (long) ((b - a + 1) * Random()));}  int main(void){  long   i;                               /* replication index      */  long   x;                               /* sum of three dice      */  long   count[19] = {0};                 /* histogram              */  double p[19]     = {0.0};               /* probability estimates  */  PutSeed(0);  for (i = 0; i < N; i++) {    x = Equilikely(1, 6) + Equilikely(1, 6) + Equilikely(1, 6);    count[x]++;  }  for (x = 3; x < 19; x++)                /* estimate probabilities */    p[x] = (double) count[x] / N;  printf("\nbased on %ld replications ", N);  printf("the estimated probabilities are:\n\n");  for (x = 3; x < 19; x++)    printf("p[%2ld] = %5.3f\n", x, p[x]);  printf("\n");  return (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -