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());
}
اما نمیشه ممنون میشم راهنماییم کنید
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());
}
اما نمیشه ممنون میشم راهنماییم کنید