int num;
num=ran(1)*10000;

解决方案 »

  1.   

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    void main( void )
    {
    srand( (unsigned)time(NULL) );
    int n;
    n=rand();
    n=(int) n*10000/32767;
    printf( "  %d\n", n);
    }
    可以产生随机三到四位数,如果要排除三位数,做个条件判断,>999 && <10000.
      

  2.   

    RAND( ) Returns a random number between 0 and 1.Syntax:RAND([nSeedValue])Returns NumericArguments nSeedValueSpecifies the seed value that determines the sequence of values RAND( ) returns.RAND( ) returns the same sequence of random numbers if you use the same seed value for nSeedValue the first time you issue RAND( ) followed by subsequent RAND( ) function calls without nSeedValue.If nSeedValue is negative the first time you issued RAND( ), a seed value from the system clock is used. To achieve the most random sequence of numbers, issue RAND( ) initially with a negative argument and then issue RAND( ) without an argument.If you omit nSeedValue, RAND( ) uses a default seed value