Chinaunix首页 | 论坛 | 博客
  • 博客访问: 397437
  • 博文数量: 58
  • 博客积分: 1775
  • 博客等级: 上尉
  • 技术积分: 755
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-12 15:03
文章分类

全部博文(58)

文章存档

2012年(5)

2011年(43)

2010年(10)

分类: LINUX

2011-11-02 10:37:31

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <time.h>


  6. int GetPrice(int old_prince)
  7. {
  8.     int new_price,rand_data;
  9.     //初始化一个随机数种子
  10.     srand((int)time(0));
  11.     //产生一个0-99的一个随机数
  12.     rand_data = (int) (rand()*100.0/RAND_MAX);
  13.     //概率性涨价变化
  14.     if(rand_data < 85) new_price = old_prince -10;
  15.     else new_price = old_prince;
  16.     return new_price;
  17. }

  18. int main(void)
  19. {
  20.     printf("old_price=32,new_prince=%d\n",GetPrice(32));
  21.     sleep(1);
  22.     printf("old_price=36,new_prince=%d\n",GetPrice(36));
  23.     sleep(2);
  24.     printf("old_price=39,new_prince=%d\n",GetPrice(39));
  25.     sleep(1);
  26.     printf("old_price=67,new_prince=%d\n",GetPrice(67));
  27. }
  28. /*
  29.  *执行结果
  30. old_price=32,new_prince=22
  31. old_price=36,new_prince=36
  32. old_price=39,new_prince=29
  33. old_price=67,new_prince=57
  34. */
阅读(1153) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~