I am creating a Random Number Guessing game, but I have run into the problem of the Generator generating the same number unless I close it and reopen it. I have "Your number is too small/large". That works. But I want the number to change once the button has been clicked to check the guess. Any idea's of what is wrong?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Guess_the_number_1
{
public partial class Form1 : Form
{
int randomNumber;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Random random = new Random();
randomNumber = random.Next(0, 10);
}
private void buttonCheckGuess_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(textboxGuess.Text) == randomNumber)
{
MessageBox.Show("Your Guessed Correctly! The Number Is: " + textboxGuess.Text);
}
else if (Convert.ToInt32(textboxGuess.Text) < randomNumber)
{
MessageBox.Show("The Number Is Larger Than: " + textboxGuess.Text);
}
else if (Convert.ToInt32(textboxGuess.Text) > randomNumber)
{
MessageBox.Show("The Number Is Smaller Than: " + textboxGuess.Text);
}
else
{
MessageBox.Show("Your Guessed Incorrectly. The Random Number Is Not: " + textboxGuess.Text);
}
}
}
}