Jump to content
  • Advertisement

Archived

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

rob64464

Random Numbers (C# winforms)

This topic is 5466 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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]

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
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!