4
我已经创建了一个使用兰特(程序)来产生重复数C.兰特()不符合高斯分布和中心极限定理
但是重复的次数不遵循Central Limit Theorem
任何人都可以解决这个兰特()错误的问题,或者有没有其他替代使用兰特()C库来生成更好的随机数?
下面是截图:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define TOTAL_THROW 10000000
typedef enum _COINTOSS {
UNDEFINED = 0,
HEAD = 1,
TAIL = 2
} COINTOSS;
COINTOSS toss_coin() {
int x = rand() % 2;
if (x == 0) return HEAD;
else if (x == 1) return TAIL;
}
void main() {
int x, i, j, v1 = 0, v2 = 200, total = 0;
int head_range[25] = {0};
int tail_range[25] = {0};
int no_range = 0;
int count = 0;
int repeated = 0;
COINTOSS previos_toss = UNDEFINED;
COINTOSS current_toss;
srand(time(NULL));
for (i=0; i<TOTAL_THROW; i++) {
current_toss = toss_coin(); // current toss
if (previos_toss == current_toss) {
count++;
} else {
if (current_toss == HEAD) head_range[count] += 1;
else if (current_toss == TAIL) tail_range[count] += 1;
previos_toss = current_toss;
count = 0;
}
}
for (i=24; i>=0; i--) {
printf("+%d = %d\n", i+1, head_range[i]);
}
puts("________________\n");
for (i=0; i<25; i++) {
printf("-%d = %d\n", i+1, tail_range[i]);
}
printf("\nTOTAL_THROW: %d\n", TOTAL_THROW);
printf("\nPress [ENTER] to exit. . .");
getchar();
}