I'm trying to generate the same random numbers for the same seed in C whenever the user runs the program. So for example if the user runs it with "123" as the seed, it may return something like "23 45 65 71 3 13 ...", and I want the program to return the exact same sequence of numbers every time it runs with the same seed. This is what I have so far and it returns a different sequence of numbers of every time (it generates a new number every time a key other than q and enter is pressed):
void generateRandomNum(int seed) {
char c = getchar();
char quit = 'q';
int random;
srand(seed);
while (c != quit){
if (c != '\n') {
random = rand() % 75 + 1; //a random num in the range 1-75
printf("%d\n", random);
}
c = getchar();
}
printf("goodbye!");
}
What should I do?
Aucun commentaire:
Enregistrer un commentaire