Archived

This topic is now archived and is closed to further replies.

rob64464

Random Numbers (C# winforms)

Recommended Posts

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

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites