请问VC中随机函数random(),和randomize()函数不是放在stdlib.H的头文件中吗?
小弟做一到题用到这两函数,把stdlib.h头文件加入其中
可它老提示这两个是未申请的标实符....
另外也加了些time.h,stdio.h等头文件!!还是一样
请高手教下咋解决??

解决方案 »

  1.   

    use rand and srand
    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>void main( void )
    {
       int i;   /* Seed the random-number generator with current time so that
        * the numbers will be different every time we run.
        */
       srand( (unsigned)time( NULL ) );   /* Display 10 numbers. */
       for( i = 0;   i < 10;i++ )
          printf( "  %6d\n", rand() );
    }
      

  2.   

    我知道rand()也可以用...
      不过我想设定取值的范围,这样用random()不是更方面吗?
      

  3.   

    rand之后再求模也可以实现你的功能吧
      

  4.   

     
    #include <stdlib.h>
     The constant RAND_MAX is the maximum value that can be returned by the rand function. RAND_MAX is defined as the value 0x7fff.
    用rand函数配合这个常量RAND_MAX可以得到你需要的随机数范围gcc和borland的编译器用random,MS的编译器用rand