C#中怎么生成4位随机数???

2025-02-27 01:04:48
推荐回答(4个)
回答1:

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 随机数

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

      Random rad = new Random();//实例化随机数产生器rad;

       int value = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数;

       label1.Text = value.ToString(); //用label控件label1显示产生的四位随机数;

     }

    }

}

回答2:

Random r = new Random();
label1.Text = r.Next(1000, 10000).ToString();

回答3:

利用random函数就可以啊

回答4:

怎样才能生成完全的随机数啊!!~