user601367 user601367 - 1 year ago 98
C# Question

How to avoid number repetition

Hashtable values = new Hashtable();

protected void Button1_Click(object sender, EventArgs e)
Random r = new Random();
int newval = r.Next(10);


//foreach (object value in values.Values)
// Response.Write(value.ToString());

ArrayList arrayList = new ArrayList(values.Values);
foreach (int key in arrayList)

Answer Source

It's random. By definition there exists a statistical possibility that numbers will repeat. It's possible that you can add 10 random integers from 1-10 to a list and that they wouldn't repeat, but it would be unlikely.

Ideally, each time you call a randomization function, you have exactly the same odds of getting any one number as you do of getting any other number, including the number you got last time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download