C# 로또 번호 추첨기
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Lotto
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Random rnd = new Random();
int min = 1;
int max = 46;
int[] arrint = new int[7];
private void button1_Click(object sender, EventArgs e)
{
for (int count = 0; count <= 6; count++)
arrint[count] = rnd.Next(min, max);
for (int count = 0; count <= 6; count++)
{
for (int scount = count + 1; scount <= 6; scount++)
{
for (; arrint[count] == arrint[scount]; )
arrint[scount] = rnd.Next(min, max);
}
}
lbl_1.Text = Convert.ToString(arrint[0]);
lbl_2.Text = Convert.ToString(arrint[1]);
lbl_3.Text = Convert.ToString(arrint[2]);
lbl_4.Text = Convert.ToString(arrint[3]);
lbl_5.Text = Convert.ToString(arrint[4]);
lbl_6.Text = Convert.ToString(arrint[5]);
lbl_bonus.Text = Convert.ToString(arrint[6]);
}
}
}
가끔가다 중복되는 경우가 있네요.
공부를 안했더니 중복 데이터를 걸러내는게 생각이 안나네요..