I'm a complete beginner programmer trying to make a random number generator in C that asks the user for their preferred range and how many times they want a random number generated. My issue is that when the user wants more than one number generated, all those numbers are the same.. It's a random number with each run but when the for loop runs it always duplicates the first number.. Is this somehow fixed with pointers and arrays? Like create an array where its size is how many times the user wants a random number and use pointer arithmetic to access each block of the array where a separate random number is generated?
Anyways, this is my code until now, sorry if the formatting is bad:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int makeCalc(int a, int b){
int z;
int calc2;
srand(time(NULL));
calc2=rand()%((a-b)+1)+b;
printf("%i \n", calc2);
return calc2;
}
int main (void){
int lower, upper, calc, range,x;
printf("Random number generator!\nEnter your preferred lower range:");
scanf("%i", &lower);
printf("Enter the upper range:");
scanf("%i", &upper);
printf("How many random numbers do you want generated?");
scanf("%i", &range);
if(range==0){ //in case user puts 0 times..
printf("Enter a positive integer:");
scanf("%i", &range);
}
srand(time(NULL));
calc=rand()%((upper-lower)+1)+lower;
if(range==1){
printf("Your random number is: ");
printf("%i \n", calc);
}
if(range>0){
for(x=0;x<range;x++)
makeCalc(upper,lower);
}
}