从34.700到34.800之间产生1000个随机数
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 TEST
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Suiji()
{
string result= "";
//定义一个随机类Random的对象,并初始化
System.Random rad = new Random();
for (int i = 0; i < 1000; i++)
{
//从0到1000中随机产生一个数(取不到0和1000)
double n1 = rad.Next(1000);
//除以10000得到所需小数
double n2 = n1 / 10000;
double n3 = n2 + 34.7;
result += n3.ToString() + " ";
}
textBox1.Text = result;
}
/// <summary>
/// 主窗体加载事件,同时调用自定义的方法Suiji()
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Load(object sender, EventArgs e)
{
Suiji();
}
}
}