当前位置:网站首页>Simulation of the Saier lottery to seek expectation
Simulation of the Saier lottery to seek expectation
2022-06-28 11:35:00 【Xiongsanming】
Nine cards , At first it was the opposite , Take three cards at random each time to change the face , The next extraction is based on this , Stop until all cards are timed . Find the expectation of extraction times . And calculate the probability of completing the extraction within 200 times .
There are three... Through binary bits 1 Iterative XOR of random numbers , Achieve the effect of continuous turnover . Because in binary 1 The number of digits is 3 There are only 84 Kind of , So you can use a three-tier loop to store it in s[84] in , You can sort and verify .
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int s[84]={0};
int cmp(const void *a,const void *b){
return *(int*)a-*(int*)b;}
int produce_random(void){
int n=rand()&511;
return n;
}
int randni(void){
int n=rand()%84;
return n;}
int expbi(const int n){
int m=1<<n;
return m;}
int main(int argc, char** argv){
int i=0,j,k,l;
int a,b,c;
int v=1000000;
for(j=0;j<7;j++){
for(k=j+1;k<8;k++){
for(l=k+1;l<9;l++){
s[i++]=expbi(j)+expbi(k)+expbi(l);
}
}
}
float sum=0.0;
//qsort(s,84,sizeof(int),cmp);
srand((unsigned int)time(NULL));
for(i=0;i<v;i++){
a=0;
for(k=0;k<100000;k++){
b=randni();
b=s[b];
a=a^b;
if(a==511)break;
}
// printf("%d\n",k);
sum+=k;
// if(k<200)
//sum+=1;
}
sum/=v;
printf("%f",sum);
/* for(i=0;i<84;i++)
printf("%d\n",s[i]);*/
return 0;
}
The result of calculating the expected mean value a million times

Probably 517 Times or so
Here is 200 Probability of success

边栏推荐
- Graduation season, some suggestions for you who are new to the society
- Xshell和Xftp使用教程
- MySQL cannot query the maximum value using the max function
- Packaging and publishing application of jetpack compose desktop version
- Making and using of dynamic library (shared library)
- 2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
- Download and install mysql5.7 for windows 10
- day31 js笔记 DOM下 2021.09.26
- 【剑指Offer】49. 丑数
- Everyone can participate in open source! Here comes the most important developer activity in dragon lizard community
猜你喜欢

Array method in JS 2021.09.18

For example, the visual appeal of the live broadcast of NBA Finals can be seen like this?

vsftpd服务的部署及优化

day37 js笔记 运动函数 2021.10.11

Day39 prototype chain and page fireworks effect 2021.10.13

Jetpack Compose Desktop 桌面版本的打包和发布应用

网页提示此站点不安全解决方案

智联招聘基于 Nebula Graph 的推荐实践分享

水果FL Studio/Cubase/Studio one音乐宿主软件对比

day32 js笔记 事件(上)2021.09.27
随机推荐
Thesis reading (59):keyword based diverse image retrieval with variable multiple instance graph
Day33 JS note event (Part 2) September 28, 2021
Web page tips this site is unsafe solution
Training notice | special training notice on epidemic prevention and security prevention for overseas Chinese funded enterprises, institutions and personnel in 2022
使用logrotate对宝塔的网站日志进行自动切割
静态库的制作和使用
Xshell and xftp tutorial
js中this的默认指向及如何修改指向 2021.11.09
Splicing strings in the string collection_ Stream based
Day28 strict mode, string JS 2021.09.22
Docker modifies the user name and password of MySQL
Day39 prototype chain and page Fireworks Effect 2021.10.13
Oracle 日期格式化异常:无效数字
使用API快捷创建ECS
Graduated
day39 原型链及页面烟花效果 2021.10.13
MySql5.7添加新用户
day23 js笔记 2021.09.14
day36 js笔记 ECMA6语法 2021.10.09
李宏毅《机器学习》丨7. Conclusion(总结)