软件编程
位置:首页>> 软件编程>> C#编程>> C#实现的简单随机数产生器功能示例

C#实现的简单随机数产生器功能示例

作者:lovequanxin  发布时间:2023-06-05 12:57:54 

标签:C#,随机数

本文实例讲述了C#实现的简单随机数产生器功能。分享给大家供大家参考,具体如下:

运行效果如下:

C#实现的简单随机数产生器功能示例

具体代码如下:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Math
{
 public partial class Form1 : Form
 {
   public Form1()
   {
     InitializeComponent();
   }
   System.Random t=new System .Random() ;//初始化随机数函数
   string num;//定义一个字符串变量,用于显示
   private void button1_Click(object sender, EventArgs e)
   {
     timer1.Start();
   }
   private void button2_Click(object sender, EventArgs e)
   {
     timer1.Stop();
   }
   private void timer1_Tick(object sender, EventArgs e)
   {
     this.num = Convert.ToString(t.Next(1,1000));//产生1到1000之间的一个随机数
     textBox1.Text = num;
   }
   private void button3_Click(object sender, EventArgs e)
   {
     this.Close();//关闭程序
   }
 }
}

PS:这里再为大家提供几款功能类似的在线工具供大家参考:

在线随机数字/字符串生成工具:
http://tools.jb51.net/aideddesign/suijishu

在线随机字符/随机密码生成工具:
http://tools.jb51.net/aideddesign/rnd_password

高强度密码生成器:
http://tools.jb51.net/password/CreateStrongPassword

希望本文所述对大家C#程序设计有所帮助。

来源:http://blog.csdn.net/lovequanxin/article/details/5538557

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com