المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Need the code for Randomization of numbers using c#



C# Programming
10-05-2009, 10:13 PM
I have used the following code. when the "Quescnt" and the "max value(Int32.Parse(ds.Tables[1].Rows[cnt-1][0].ToString()))" are equal, its going to infinite loop.

static int TheSeed = (int)DateTime.Now.Ticks;
Random RandomClass = new Random(TheSeed);

string Randomnos = string.Empty;

for (int i = 0; i < Quescnt ; i++)
{
int RandomNumber = RandomClass.Next(Int32.Parse(ds.Tables[1].Rows[0][0].ToString()), Int32.Parse(ds.Tables[1].Rows[cnt-1][0].ToString()));
if (!Randomnos.ToString().Contains(RandomNumber.ToString() + ","))
{
Randomnos = Randomnos + RandomNumber.ToString() + ", ";
}
else
{
Quescnt++;
}
}