dimanche 5 avril 2020

Fill an array with 4 unique random numbers in C

For a school project I need to do MasterMind, and all the 4 numbers of the secret code have to be different.

How can I create an array with 4 unique random numbers?

Here is my code so far:

srand(time(NULL));

for (j = 0; j <= 4; j++) { rand(); } 

for (i = 0; i < 4; i++) { vetor[i] = (1 + rand() % 8); }



Aucun commentaire:

Enregistrer un commentaire