Hi I'm trying to generate a random number betwen any numbers (eg from 1 to 100) and I've tried this code:
#include<stdio.h>
#include<math.h>
#include<time.h>
#include <stdlib.h>
int NumAleatori(int max)
{
int num;
num=((int)ceil(((double)rand()/RAND_MAX)*(max+1)))%(max+1);
return num;
}
void main ()
{
int N,a;
srand( (unsigned)time( NULL ) );
printf(“Enter an integer:\”);
scanf(“%d”,&N);
a = NumAleatori(N);
printf(“%d”,a);
}
It does not give me random numbers. It gives me the same number for small ranges and it follows a pattern for a graters ranges.