Chinaunix首页 | 论坛 | 博客
  • 博客访问: 376287
  • 博文数量: 124
  • 博客积分: 2911
  • 博客等级: 少校
  • 技术积分: 1050
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-15 15:57
文章分类

全部博文(124)

文章存档

2012年(6)

2011年(26)

2010年(92)

我的朋友

分类: C/C++

2010-07-13 16:46:23

#include
#include
#include
#include
#include

int count=1;

volatile int getBin(){
    int i, j;
    unsigned long ts = time(NULL);

    count += 12497023;
    srand((unsigned int)ts * count);
    j=rand();

    if(j>(RAND_MAX/3))
        return 1;
    else return 0;
}

volatile int getBin_N(){
    int i, j;
    unsigned long ts = time(NULL);

    count += 12497023;
    srand((unsigned int)ts * count);

    j=rand();

    if(j>(RAND_MAX/3))
        return 0;
    else return 1;
}

int main()
{
    double c=0,t=0;
    while(1)
    {
        t+=2;
        c+=(double)getBin()+(double)getBin_N();
        printf("ratio=%5.2f\%\r\b",c / t * 100.0);
    }
    return 0;
}

阅读(565) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~