[ create a new paste ] login | about

Link: http://codepad.org/x2U3z0Q0    [ raw code | output | fork ]

C, pasted on Sep 11:
#include<stdlib.h>
main(){
	double x[6]={9.0/50,9.0/50,9.0/50,9.0/50,9.0/50,5.0/50},s;
	int y[6],i,k,r,count,count_sum=0,mem[42];

	for(i=0,s=0.0;i<6;i++){s+=x[i];y[i]=s*RAND_MAX;}
	for(i=0;i<42;i++)mem[i]=0;
	for(i=0;i<1000000;i++){
		k=count=0;
		while(k!=63){
			r=rand();
			if(r<y[2]) k |=    1+(r>y[0]) + 2*(r>y[1]) ;
			else	   k |= 8*(1+(r>y[3]) + 2*(r>y[4]));
			count++;
		}
		count_sum+=count;
		if(count<41)mem[count]++;else mem[41]++;
	}
	printf("%f\n",(double)count_sum/1000000.0);
	for(i=0;i<42;i++)printf("%2d:%d\n",i,mem[i]);
	return 0;
}


Output:
16.042427
 0:0
 1:0
 2:0
 3:0
 4:0
 5:0
 6:13606
 7:33731
 8:52970
 9:66972
10:73931
11:76018
12:74431
13:70831
14:64898
15:58818
16:52271
17:46311
18:40779
19:35332
20:30736
21:26914
22:22800
23:20156
24:17377
25:15245
26:13209
27:11267
28:9881
29:8670
30:7535
31:5739
32:5916
33:5320
34:4477
35:4016
36:3468
37:3052
38:2707
39:2308
40:2024
41:16284


Create a new paste based on this one


Comments: