mardi 25 janvier 2022

Generating random number until they repeat in C/CPP

I have a problem with a program in C or CPP. I need to make a program that will generate a random nubers in range of 1-365, but when the program generates the same number as it allredy did, the program will write the count of numbers and repeat it self again 100 times.


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int lower = 1, upper = 365, count = 365;

    srand(time(0));

    printf("The random numbers are: ");
    for (int i = 0; i < count; i++) {
            
        int num = (rand() % (upper - lower + 1)) + lower;
        printf("%d ", num);
    }

    return 0;
}

I know how to make the generator for random numbers but i have problem with stopping it when the numbers reapeat.




Aucun commentaire:

Enregistrer un commentaire