Random Numbers (C# winforms)

Started by
4 comments, last by rob64464 20 years, 6 months ago
Hi, I asked this question some time a go. But I cannot seem to generate 10 random numbers in a windows form! How do you generate 10 Random numbers in C#? It must be compatgable with windows forms! Cheers Guys, Rob
Advertisement
Random rnd = new Random();for(int i = 0; i < 10; ++i)   int number = rnd.Next();   


Has nothing to do with WinForms anyway

Regards,

VizOne

[edited by - VizOne on October 8, 2003 1:48:26 PM]
Andre Loker | Personal blog on .NET
I get a error! ''C:\Documents and Settings\Robert\My Documents\Programming\random\Form1.cs(551): Embedded statement cannot be a declaration or labeled statement''

it highlights ''int''
int number = rnd.Next();
I fixed error! But what I want it to do is pick a number from 1 to 10

if (number==5) MessageBox.Show("the random number between 1 and 10 was 5");

thanks a lot this will be a great help :-)
Rob
rnd.next(int a, int b); //where a & b are min and max of the range.

be aware that the second argument is the bound, and not the upper limit. for 1 - 10, you'd use 1 and 11.

all of this is in the VS.NET documentation

[edited by - mirirom on October 8, 2003 7:19:31 PM]
..:: mirirom ::..
It be easier to code your messagebox like this:

MessageBox.Show("The random number between 1 and 10 was " + number);

That way you don''t have to make 9 if''s and an else.
Michael BartmanCEO, Lead ProgrammerDark Omen Studios

This topic is closed to new replies.

Advertisement