Hello,
Actually i want to generate more than 1 random from given reng od minumum and maximum value from textbox on button click
. aspx..-------------
Minimum value
Maximum value
Result :
OnClick="Button1_Click" Text="Generate Random Number in a Rage" />
.cs-----------
protected void Button1_Click(object sender, EventArgs e)
{
//------1
Random r1 = new Random();
int num = r1.Next(
Convert.ToInt32(TextBox1.Text),
Convert.ToInt32(TextBox2.Text)
);
////----- 2
//Random r2 = new Random();
//int num2 = r2.Next(
// Convert.ToInt32(TextBox1.Text),
// Convert.ToInt32(TextBox2.Text)
// );
////----- 2
//Random r3 = new Random();
//int num3 = r3.Next(
// Convert.ToInt32(TextBox1.Text),
// Convert.ToInt32(TextBox2.Text)
// );
////----- 2
//Random r4 = new Random();
//int num4 = r4.Next(
// Convert.ToInt32(TextBox1.Text),
// Convert.ToInt32(TextBox2.Text)
// );
lblnumber.Text = "First No." + num.ToString(); // +", 2nd No." + num2.ToString() + ", No.3 " + num3.ToString() + ", 4th No." + num4.ToString();
//Response.Write(num.ToString());
NewNumber();
}
public Random a = new Random(); // replace from new Random(DateTime.Now.Ticks.GetHashCode());
// Since similar code is done in default constructor internally
public List randomList = new List();
int MyNumber = 0;
private void NewNumber()
{
MyNumber = a.Next(0, 10);
if (!randomList.Contains(MyNumber))
randomList.Add(MyNumber);
}
With is code , i get only one random number on every click, But i want minimum 4 random number .
Please chack and resolve this problem.
1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Amit KumarPosted Nov 8, 2017, 7:22 AM