PDA

View Full Version : مشکل در تولید اعداد تصادفی



saman6488
سه شنبه 01 آذر 1390, 10:13 صبح
با سلام دوستان من یه تابع رندوم به شکل زیر تعریف کردم

IEnumerable<int> UniqueRandom(int minInclusive, int maxInclusive)
{
List<int> candidates = new List<int>();
for (int i = minInclusive; i <= maxInclusive; i++)
{
candidates.Add(i);
}
Random rnd = new Random();
while (candidates.Count > 1)
{
int index = rnd.Next(candidates.Count);
yield return candidates[index];
candidates.RemoveAt(index);
}
حالا مشکلی که دارم اینه که میخام تو این اعداد تصادفی مثلا 70 تا رو نشون بدم حالا برا این کار اینجور عمل کردم

foreach (int i in UniqueRandom(0, 48694))
{

for (int tem = 1; tem < 70; tem++)
{
listBox1.Items.Add(tem.ToString());
}
اما نمیشه ممنون میشم راهنماییم کنید

Saman Hashemi
سه شنبه 01 آذر 1390, 13:50 عصر
Random rnd= new Random();
int count = 70;
int max = 4000;
int min = 0;
int[] iRan = new int[count];
for (int j = 0; j < count; j++)
{
iRan[j] = rnd.Next(min, max);
}