2015年10月22日 星期四

亂數不重複

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;

    public partial class Form1 : Formnamespace WindowsFormsApplication1
{
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void button10_Click(object sender, EventArgs e)
        {
            Random rnd = new Random();
            button1.Text = rnd.Next(0, 9).ToString();
            button2.Text = rnd.Next(0, 9).ToString();
            button3.Text = rnd.Next(0, 9).ToString();
            button4.Text = rnd.Next(0, 9).ToString();
            button5.Text = rnd.Next(0, 9).ToString();
            button6.Text = rnd.Next(0, 9).ToString();
            button7.Text = rnd.Next(0, 9).ToString();
            button8.Text = rnd.Next(0, 9).ToString();
            button9.Text = rnd.Next(0, 9).ToString();
            while (button1.Text == button2.Text)
            {
                button2.Text = rnd.Next(0, 9).ToString();
            }
            while (button2.Text == button3.Text || button1.Text == button3.Text)
            {
                button3.Text = rnd.Next(0, 9).ToString();
            }
                   while(button3.Text == button4.Text);
                 
        }}}
 

沒有留言:

張貼留言