I have created a small app to generate a random number on a button click and at the moment I am saving that number in a .txt file.
private void button1_Click(object sender, EventArgs e)
{
Random rnd = new Random();
int random = rnd.Next(1, 10000);
// saving to a file is not an option!
//File.AppendAllText(@"C:\Users\Public\no.txt", random + Environment.NewLine);
}
The problem to solve is that this random generated number must be unique (range from 1 to 9999) so every time when the number is generated I would check if that number was generated previously. But to do that I must keep a record of every generated number to be able to check, compare and if exists generate a new one until all numbers are used.
So the question is: Is it possible somehow to keep a record inside app so that I don't have to create any additional files?
update
After closing the app, previously numbers must be saved to be able to create unique new numbers!