From 82f07c959dc7a87251b4617e462003471e3cc071 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Mon, 9 Apr 2018 00:54:19 +0200 Subject: Refactoring and Cleanup --- DiscoBot/Auxiliary/Misc.cs | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 DiscoBot/Auxiliary/Misc.cs (limited to 'DiscoBot/Auxiliary/Misc.cs') diff --git a/DiscoBot/Auxiliary/Misc.cs b/DiscoBot/Auxiliary/Misc.cs new file mode 100644 index 0000000..2531f12 --- /dev/null +++ b/DiscoBot/Auxiliary/Misc.cs @@ -0,0 +1,51 @@ +namespace DiscoBot.Auxiliary +{ + using System; + using System.Linq; + using System.Text; + + public static class Misc + { + private static readonly Random Rand = new Random(); + + // use: 4w6 +4 + public static string Roll(string input) + { + var output = new StringBuilder(); + var strings = input.Split('w', 'd').ToList(); + int count = Convert.ToInt32(strings[0]); + strings = strings[1].Split(' ').ToList(); + int d = Convert.ToInt32(strings[0]); + + if (strings.Count > 0) + { + } + + int sum = 0; + for (int i = 0; i < count; i++) + { + var roll = Dice.Roll(d); + sum += roll; + output.Append("[" + roll + "] "); + } + + if (count > 1) + { + output.Append("sum: " + sum); + } + + return output.ToString(); + } + + public static double Random(double stdDev = 1, double mean = 0) + { + double u1 = Rand.NextDouble(); // uniform(0,1) random doubles + double u2 = Rand.NextDouble(); + double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * + Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) + double randNormal = + mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) + return randNormal; + } + } +} -- cgit v1.2.3-70-g09d2