代码如下: srand((unsigned)time( NULL ) );
int rate = rand() % 10000;
::MessageBox(NULL,itostring(rate).c_str(),"",0); 

解决方案 »

  1.   

    int rate = rand() % 10000;
    int 型数据类型有上限限制,不可能太大,你再除了10000,那就更小了。
      

  2.   

    应该是产生0-9999之间的值,不过计算机快的话,可能会产生连继一样的值while(true)
    {
      srand((unsigned)time(NULL));
      int rate = rand() % 10000;
    }
      

  3.   

    我只是用来取 0~9999 的随机数, 用来控制概率,比如50%概率就 >5000做,<5000不做。  结果是一段时间内 要么每次都做(>5000),要么就每次都不做(<5000)。
      是不是用时间做种子,在一定时间内不可能真正随机?
      

  4.   

    应该这样写把:srand((unsigned)time(NULL));while(true)
    {
      int rate = rand() % 10000;
    }
      

  5.   

    srand((unsigned)time(NULL));在程序的一次运行中,这句话只需要执行一次就够了