zoukankan      html  css  js  c++  java
  • 随机数的使用

    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;
    using System.Threading;
    
    namespace 摇奖机
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.Text = "抽奖机";
                button1.Text = "开始";
                Control.CheckForIllegalCrossThreadCalls = false;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if(b == false)
                {
                    b = true;
                    button1.Text = "停止";
                    Thread th = new Thread(PlayGame);
                    th.IsBackground = true;
                    th.Start();
                    //PlayGame();
                }
                else
                {
                    b = false;
                    button1.Text = "开始";
                }
    
            }
    
            bool b = false;
            private void PlayGame()
            {
                //随机数的使用
                Random r = new Random();
                while(b)
                {
                    //在[0-9]整数
                    label1.Text = r.Next(0, 10).ToString();
                    label2.Text = r.Next(0, 10).ToString();
                    label3.Text = r.Next(0, 10).ToString();
                    Thread.Sleep(100);
                }
            }
        }
    }
    

      

  • 相关阅读:
    1023. 组个最小数
    1021. 个位数统计
    *1020. 月饼
    *1019. 数字黑洞
    1016. 部分A+B
    *1014. 福尔摩斯的约会
    *1013. 数素数
    *1012. 数字分类
    1011. A+B和C
    *1008. 数组元素循环右移问题
  • 原文地址:https://www.cnblogs.com/my-cat/p/7428858.html
Copyright © 2011-2022 走看看