mardi 18 mai 2021

C - How can I make a loop that prints out random numbers 'n' amount of times? [duplicate]

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

int main(){
    
    for(int i = 0; i < 10; i++){
       srand(time(NULL)); 
       int computer = (rand() / ((double) RAND_MAX + 1)) * 5;
       printf("%d\n", computer);
    
    }
    
    return 0;
}

I'm new to programming and this is what I have done so far. The problem is that it will generate a random number and print that same number 10 times instead of printing out 10 random numbers. How do I solve this?




Aucun commentaire:

Enregistrer un commentaire