I have a program to generate random lottery numbers in WPF but I don't know how to get unique random numbers. I got this exercise after I studied about the 'if structure' so I guess I should use that somehow but I have no idea how.
Here is my code:
private void btnGo_Click(object sender, RoutedEventArgs e)
{
Random rd = new Random();
int marginLeft = 50 + (caPaper.Children.Count * 50);
Ellipse newBall = new Ellipse();
newBall.Fill = new SolidColorBrush(Colors.Red);
newBall.Height = 70;
newBall.Width = 70;
newBall.Margin = new Thickness(marginLeft, 100, 0, 0);
caPaper.Children.Add(newBall);
TextBlock txt1 = new TextBlock();
txt1.FontSize = 20;
txt1.Foreground = Brushes.White;
txt1.Text = " " + rd.Next(1, 45);
Canvas.SetTop(txt1, 120);
Canvas.SetLeft(txt1, marginLeft + 20);
caPaper.Children.Add(txt1);
}
private void btnClear_Click(object sender, RoutedEventArgs e)
{
caPaper.Children.Clear();
}