mardi 7 septembre 2021

Is there an Code for Generating a Random Number without Repeating

I have this code only , My code does only to print the BINGO Table. I can't generate a randomize number and place it to a correct column and cell.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bingo
{

class Program
{
    private const int BingoSpacing = 5;
    private const int BingoCardLength = 5;
    private const int BingoCardAmount = 3;

    private static Random random = new Random();

    static void Main(string[] args)
    {
        for (int i = 0; i < BingoCardAmount; i++)
        {

            var table = new string[BingoCardLength, BingoCardLength];
            PrintBoard(table);
            Console.WriteLine();
        }
        Console.ReadKey();

    }

This is my code in Printing the BINGO Table. The BINGO table works , but the print numbers it wont work. I don't know how to use the Random Number. I only know the basics , since the number needs to be at B = (1,15) I = (16,-30) N = (31,45) G = (46 - 60) I = (61,75)

    private static void PrintBoard(string[,] table)
    {
        // print the title
        string[] headings = { "B", "I", "N", "G", "O" };
        for (var i = 0; i < headings.Length; i++)
        {
            Console.Write(headings[i].PadRight(BingoSpacing));
        }
        Console.WriteLine();

        // print the numbers
        for (var i = 0; i < table.GetLength(0); i++)
        {
            for (var j = 0; j < table.GetLength(1); j++)
            {
                // im getting a error here
                //Console.Write(table[i, j].PadRight(BingoSpacing));
            }
            Console.WriteLine();
        }
    }
}

}




Aucun commentaire:

Enregistrer un commentaire