大家好,小弟在练习vc时,遇到一个问题,temp=random(100);语句。我在编译时,它告诉我random没有定义,这是怎么回事?

解决方案 »

  1.   

    VC中产生随机数用rand()之前#include <stdlib.h>
      

  2.   

    The code is in the MSDN
    #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() );
    }
    Output    6929
        8026
       21987
       30734
       20587
        6699
       22034
       25051
        7988
       10104