jeudi 29 mars 2018

Output Random Number > range when using rand() function in C

My Specific question is when i input a range like 90 as the lower value and 100 as the higher value i get output random number sometimes less than 90.In my code below , x<y. My code is:

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


}   




Aucun commentaire:

Enregistrer un commentaire