::srand((unsigned int)time(NULL)); //先初始化int x=rand();    //随机

解决方案 »

  1.   

    ::srand((unsigned int)1); //先初始化
    int x=rand()%10;    //产生0-9的随机数
      
      

  2.   

    #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() );
    }