If I may step in and make some constructive comments...
Code:
private void button1_Click(object sender, EventArgs e)
{
//this is the initialisation of what you had in the loop as Raven mentioned. As a rule never try to initialise in a loop.
int [] niz = new int[100];
Random m = new Random();
for (int i = 0; i < 100; i++)
{
Random m = new Random();//so this disappears
int ZOMG = m.Next(0,100);//remove this line
niz[i] = ZOMG;//ZOMG is a fluffy extra variable you don't need. Do the line below
... niz[i] = m.Next(0,100); ... //this just puts the random number straight in to your array.
listBox1.Items.Add(Convert.ToString(niz[i]));//ZOMG changed to niz[i]
i = i + 1;//not needed, the for loop increments 'i' by one anyway
}
}
Now I am probably going a bit too far, but here's the clean version -
Code:
private void button1_Click(object sender, EventArgs e)
{
int [] niz = new int[100];
Random m = new Random();
for (int i = 0; i < 100; i++)
{
niz[i] = m.Next(0,100);
listBox1.Items.Add(Convert.ToString(niz[i]));
}
}
However, just as I started this in notepad++ so I could see what I was doing, I realised this is the fastest way, just throw the random number straight in to the actual listbox itself! The reason being niz[i] is not actually available to any other part of the program. I am not clear on whether you need to use niz[i] anywhere else though, but this next bit assumes you don't:
Code:
private void button1_Click(object sender, EventArgs e)
{
Random m = new Random();
for (int i = 0; i < 100; i++)
{
listBox1.Items.Add( Convert.ToString( m.Next(0,100) ) );
}
}
If you do need to access niz[i], you could easily just do the last bit of code I gave, but refer to the listbox location you want to look at.
so instead of calling say :
Code:
randomVariableName = niz[randomNumber];
this would allow you to call the number directly from the listbox :
Code:
randomVariableName = listBox1.Items.IndexOf(randomVariableGetter);
There are many ways of grabbing something from a listbox, I believe that is one of them.
I hope I have been some help!