// Rand.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char* argv[])
{
int i,j;
srand( (unsigned)time( NULL ) );
int total[2] = {0};
int temp = 0;
for( i = 0; i < 1000000;i++ )
{
temp = rand()%2;
printf( " %d\n",temp);
total[temp]++;
}
printf("############################################################################\n");
for(j = 0; j < 2; j++)
{
printf("total[%d]=%d\n",j,total[j]);
}
system("pause");
return 0;
}
/*
结果:
第一组:
total[0]=500026
total[1]=499974
第二组:
total[0]=500159
total[1]=499841
第三组:
total[0]=500023
total[1]=499977
第四组:
total[0]=500034
total[1]=499966
第五组:
total[0]=499962
total[1]=500038
第六组:
total[0]=499898
total[1]=500102
第七组:
total[0]=500002
total[1]=499998
第八组:
total[0]=499991
total[1]=500009
第九组:
total[0]=500106
total[1]=499894
第十组:
total[0]=499997
total[1]=500003
*/