Making a bingo game in c# visual studio, windows forms. I made a random populate
ID: 3592685 • Letter: M
Question
Making a bingo game in c# visual studio, windows forms. I made a random populated array, without duplicates, for called numbers. I need to print the next element in the array when the "next" button is clicked that prints after the previously called printed numbers (so 14 additional clicks after the initial click). I see why it is printing all elements at once, but I cannot figure out how make it not do that. Show me code that works please? Unsure how to make a call that works when I click the "Next" button. I've only had a few weeks learning c# with little other experience. Please and thanks! The code I have so far is below:
private void btnNext_Click(object sender, EventArgs e)
{
//array "called" is global
lblNumCalled.BackColor = Color.Yellow;
int i = 1;
if (called == null)
{
Random rand = new Random();
int randNumber = rand.Next(1, 16);
called = Enumerable
.Range(1, 15) // number 1 - 15
.OrderBy(x => rand.Next()) // randomly shuffled
.Take(15) // we only need 15
.ToArray(); // as an array please.
lblNumCalled.Text = Convert.ToString(called[0]);
lblListOfCalled.Text = Convert.ToString(called[0]);
}
else
{
for (i = 1; i < called.Length; i++)
{
lblNumCalled.Text = Convert.ToString(called[i]);
lblListOfCalled.Text += " " + called[i];
}
}
}
Explanation / Answer
you can simply make a rand funtion like this
//Generate a random number between two givin
public int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
and while calling you can give parameter as 1 and 16 like :
int x = RandomNumber(1,16)
x will hold that randon int.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.