016 生成随机数

#include "stdafx.h"
#include <stdlib.h>
#include <time.h>

// 生成随机数 - 100到200
int main(int argc, char *argv[], char **envp)
{
    srand((unsigned)time(NULL));

    int nLoop = 0;
    while (nLoop < 20)
    {
        int i = 100 + rand() % 100;
        printf("%d\n", i);

        ++nLoop;
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/huafan/p/11553108.html