Scott Miller

Appsguild - Software craftsmanship, project management, and the biz of software

  Home  |   Contact  |   Syndication    |   Login
  153 Posts | 3 Stories | 177 Comments | 72 Trackbacks

News



Article Categories

Archives

Image Galleries

Best Blogs

Podcasts

Scott's links

Good progress on the game tonight. Added more detail to my XML files. Created classes (diagrams to be posted soon).

I found functions online for generating random die rolls.

Here are functions to roll 20 sided die and 6 sided die:
public static int Roll20SidedDie()
{
Random rNum = new Random();
int newDie = rNum.Next(20) + 1;
return newDie;
}

public static int Roll6SidedDie()
{
Random rNum = new Random();
int newDie = rNum.Next(6) + 1;
return newDie;
}

posted on Thursday, May 25, 2006 7:41 PM

Feedback

# re: Random die rolls 5/25/2006 11:03 PM Greg Young
Just as a thought ..

public static int RollNSidedDie(int n)
{
Random rNum = new Random();
int newDie = rNum.Next(n) + 1;
return newDie;
}

That way if you need a 9 sided die you don't have to write further code :)

Cheers,

Greg Young

# re: Random die rolls 5/26/2006 3:46 PM Simon
Did you need a blog post for this?

return new Random().Next(n) +1;

Cm'on!

# re: Random die rolls 5/26/2006 7:01 PM Scott Miller
What may seem easy to you wasn't completely clear to me. After all, I don't use Random in database business apps. :)

If posting saves another person five minutes then its time well spent.

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 7 and 6 and type the answer here: