Random value(in C#)
hi.....this is my question...
Write a function that generates a random integer between two integers passed as parameters. Build an ASP.NET page which allows you to enter the lower and upper limits, and generates a set of random numbers in that range.
Guide: You may use the following code for the function that generate the random integer.
Random r = new Random();
int rnd = r.Next(10);
return ((b-a)*(rnd)/10 + a);
my code in ques1.aspx.cs is
publicpartialclassQues1 : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
double min1, max1,num;
int md,randNum;
Random r=newRandom();
min1 = Convert.ToInt32(TextBox1.Text);
max1 = Convert.ToInt32(TextBox2.Text);
if (IsPostBack)
{
randNum = randomNum(min1, max1);//error appear here
Label1.Text = randomNum + " ";
}
}
int randomNum(int min, int max)
{
Random r = newRandom();
int md = r.Next(10);
return ((max - min) * (md) / 10 + min);
}
}
I couldn't solve it.....can anyone correct the error....thank u
Last edited by Banishah; June 24th, 2009 at 12:16 AM..
|