主题:请教大家一段ASP.NET代码,谢了
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
void Page_Load()
{
if (IsPostBack)
{
lblOut.Text = "";
Random MyRand = new Random();
byte intOutputCounter;
for (intOutputCounter=1; intOutputCounter< 11; ++intOutputCounter)
{
lblOut.Text += "<br>";
lblOut.Text += Convert.ToInt32((Convert.ToSByte(txtHigh.Text) -
Convert.ToSByte(txtLow.Text)) * MyRand.NextDouble() +
Convert.ToSByte(txtLow.Text));
} // end loop
} //End If
} //end Page_Load()
</script>
<html>
<head>
</head>
<body>
<form runat="server">
Please enter integers for range of random numbers.
<br />
Lowest number (min = -128):
<asp:TextBox id="txtLow" runat="server" Text="-5"></asp:TextBox>
<br />
Highest number (max = +127):
<asp:TextBox id="txtHigh" runat="server" Text="+5"></asp:TextBox>
<br />
<asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
<br />
<asp:Label id="lblOut" runat="server"></asp:Label>
<br />
</form>
</body>
</html>
MyRand.NextDouble() 这个随机数的范围是多少呢?
我运行,输入最大数"5",最小数"-5",产生的结果是:
2
0
-1
3
4
0
4
-4
-2
0
结果是2时,根据公式得(5--5)*x+-5=2,那随机数就是0.7
结果是0十,随机数就是0.5.这样理解对吗?
<script runat="server">
void Page_Load()
{
if (IsPostBack)
{
lblOut.Text = "";
Random MyRand = new Random();
byte intOutputCounter;
for (intOutputCounter=1; intOutputCounter< 11; ++intOutputCounter)
{
lblOut.Text += "<br>";
lblOut.Text += Convert.ToInt32((Convert.ToSByte(txtHigh.Text) -
Convert.ToSByte(txtLow.Text)) * MyRand.NextDouble() +
Convert.ToSByte(txtLow.Text));
} // end loop
} //End If
} //end Page_Load()
</script>
<html>
<head>
</head>
<body>
<form runat="server">
Please enter integers for range of random numbers.
<br />
Lowest number (min = -128):
<asp:TextBox id="txtLow" runat="server" Text="-5"></asp:TextBox>
<br />
Highest number (max = +127):
<asp:TextBox id="txtHigh" runat="server" Text="+5"></asp:TextBox>
<br />
<asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
<br />
<asp:Label id="lblOut" runat="server"></asp:Label>
<br />
</form>
</body>
</html>
MyRand.NextDouble() 这个随机数的范围是多少呢?
我运行,输入最大数"5",最小数"-5",产生的结果是:
2
0
-1
3
4
0
4
-4
-2
0
结果是2时,根据公式得(5--5)*x+-5=2,那随机数就是0.7
结果是0十,随机数就是0.5.这样理解对吗?