ArrayList lstNumbers = new ArrayList();
Random rndNumber = new Random();
int number = rndNumber.Next(1, max + 1);
lstNumbers.Add(number);
int count = 0;
do
{
number = rndNumber.Next(1, max + 1);
if (!lstNumbers.Contains(number))
{
lstNumbers.Add(number);
}
count++;
}
while (count <= 10 * max);
{
}
return lstNumbers;
I am trying to read through the ArrayList i just made but everytime i read through it with :
public void knop3_Click(object sender, EventArgs e)
{
int volgnummer = 0;
lstNumbers = nbs.RandomNumbers(total);
if (volgnummer < lstNumbers.Count)
{
listBox3.Items.Add(lstNumbers[volgnummer]);
volgnummer++;
}
}
it wont properly follow the ArrayList Properly but if i would use the following :
lstNumbers = nbs.RandomNumbers(total); for (int p = 0; p < lstNumbers.Count; p++) listBox1.Items.Add(lstNumbers[p]);
If i use the for function it will generate the 10 randomnumbers without duplicates.
But if i would use the button Click it will put the ArrayList Numbers in a different position and it will make duplicate numbers in the listbox3 maybe i am doing something silly i am still a beginner
Any help is appriciated
- Tim

New Topic/Question
Reply




MultiQuote





|