c++生成随机数

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void main()
{
    int min = 10; 
    int max = 30;
    srand ( time(NULL) );
    int output = min + (rand() % (int)(max - min + 1));
    printf("%d",output);
    getchar();

    return;
}


注意一定要加上红色那句 , 设置time为随机种子

这段程序是在 10和30之间生成一个随机数

posted on 2015-04-28 09:11  齐文宣  阅读(177)  评论(0编辑  收藏  举报

导航