dimanche 29 décembre 2019

my program does not pass the test.error Unlikely event: found 2424 out of 2400 times the same number on the same position. Are the cards random?

public class BingoCard
{
    public static String Card []= new String[24];

  public  static String[] getCard() {
      int cardLength = 0;
      number(1,15,0);
      number(16,30,5);`
      number(46,60,14);
      number(61,75,19);

        for (int i =  0; i < 5; i++)    Card[i]="B"+Card[i];
                cardLength+=5;
            for (int i =  cardLength; i < 5+cardLength; i++) Card[i]="I"+Card[i];
                cardLength+=5;
                for (int i =  cardLength; i < 4+cardLength; i++)  Card[i]="N"+Card[i];
                    cardLength+=4;
                 for (int i =  cardLength; i <5+cardLength; i++) Card[i]="G"+Card[i];
                        cardLength+=5;
                        for (int i =  cardLength; i < 5+cardLength; i++) Card[i]="O"+Card[i];

                return Card;
    }       

    public static void number(int min, int max, int index){
        int arr[] = new int[5];
        int temp;
    for (int i =index; i<index+5; i++ ){
        temp=(int)(min+Math.random()*(max-min+1));
            if(temp==arr[0]||temp==arr[1]||temp==arr[2]||temp==arr[3]||temp==arr[4]){
                i--;
                continue;
                }else   
        arr[i-index]=temp;
            Card[i]=String.valueOf(temp);
    }

    }

}

Can you help the association by writing a method to create a random Bingo card? A Bingo card contains 24 unique and random numbers according to this scheme: 5 numbers from the B column in the range 1 to 15 5 numbers from the I column in the range 16 to 30 4 numbers from the N column in the range 31 to 45 5 numbers from the G column in the range 46 to 60 5 numbers from the O column in the range 61 to 75

The card must be returned as an array of Bingo style numbers: { "B14", "B12", "B5", "B6", "B3", "I28", "I27", ... }




Aucun commentaire:

Enregistrer un commentaire