Here is the code...
using System;
using System.Collections.Generic;
using System.Linq;
namespace DiceUtils
{
   public static class Dice
   {
       private readonly static Random random = new Random();
       public static int Roll(int sides)
       {
           return random.Next(sides) + 1;
       }
       public static IEnumerable<int> Roll(int dice, int sides)
       {
           return Enumerable.Range(0, dice).Select(x => Roll(sides));
       }
       public static IEnumerable<int> Roll(int dice, int sides, int keep)
       {
           return Roll(dice, sides).AsQueryable().OrderByDescending(x => x).Take(keep);
       }
   }
}
 
No comments:
Post a Comment