From e6181c24124d97f2fbc932b8a68311e625463156 Mon Sep 17 00:00:00 2001 From: uzvkl Date: Tue, 11 Jun 2019 23:05:52 +0200 Subject: Move dsa related stuff to subfolder --- dsa/DiscoBot/Auxiliary/Dice.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 dsa/DiscoBot/Auxiliary/Dice.cs (limited to 'dsa/DiscoBot/Auxiliary/Dice.cs') diff --git a/dsa/DiscoBot/Auxiliary/Dice.cs b/dsa/DiscoBot/Auxiliary/Dice.cs new file mode 100644 index 0000000..f0f4def --- /dev/null +++ b/dsa/DiscoBot/Auxiliary/Dice.cs @@ -0,0 +1,31 @@ +using System; + +namespace DiscoBot.Auxiliary +{ + public static class Dice // roll it! + { + private static readonly Random Rnd = new Random(); + + public static int Roll(int d = 20) + { + return Rnd.Next(d) + 1; + } + + + public static int Roll(int count, int d) + { + if (d <= 0) return 0; + + var sum = 0; + for (var i = 0; i < Math.Abs(count); i++) + { + var roll = Roll(d); + sum += roll; + } + + sum *= Math.Abs(count) / count; + + return sum; + } + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf