Jump to content
  • Advertisement
Sign in to follow this  
avorpalbunny

Simple question about simulating a 6 sided dice.

This topic is 3910 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

I'm reading through a C# book about creating random numbers as they apply to dice and something occurred to me. The code they use is: die = (int)(generator.NextDouble() * 6) + 1; The computer randomly finds a number 0 to 1 and then * 6 and adds 1 so that the number doesn't end up being 0. It later cuts off the decimal information to get the number used for the dice. What happens if it randomly generates a 1 by chance though? 1 * 6 + 1 = 7 I suppose you could write some if statement to make 7 to 6, but is there any easier way and why is this overlooked in the book? Thanks for the help.

Share this post


Link to post
Share on other sites
Advertisement
Read the documentation (on MSDN) for the NextDouble function, specifically the "return value" part, and you will have your answer.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Read the documentation (on MSDN) for the NextDouble function, specifically the "return value" part, and you will have your answer.


Great, I found my solution. I didn't know they had a MSDN site that explains all the functions. That should help with questions I have later too. Thanks alot.

Share this post


Link to post
Share on other sites
Quote:
Original post by Instruo
In this case, wouldn't it just be easier and more straight forward to use .Next(1, 7)?


I'll look at that and see what it does, im pretty much a newb at this point.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!