lundi 30 novembre 2020

How to print random numbers from a selected sequence?

I want the program to print randomly one of these numbers:

{1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10}

Instead it prints randomly nonsense numbers

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

int main()
{
  srand( time(NULL) );
  int card;
  int deck[40] = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10};
  card = rand()% deck[40];
  printf("%d", card);
  return 0;
}

What can I do? thanks




Aucun commentaire:

Enregistrer un commentaire