【发布时间】:2018-03-29 16:43:07
【问题描述】:
我的具体问题是当我输入 90 作为 lower 值和 100 作为 higher 值的范围时,我得到的输出随机数有时小于 90.@987654322 @ 我的代码是:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define Null 0
void main(){
int x,y,a,b;
printf("Insert two numbers to create a range\n in which you want a random number to be generated:\n");
scanf("%d%d",&x,&y);
srand(time(Null));
a =( rand() + x)%y ;
printf("The Randomly Generated Number is %d.\n",a);
}
【问题讨论】:
-
(rand() % (high - low)) + low -
感谢您的帮助,不胜感激。