Add a better random number generator
This commit is contained in:
parent
fe08eee049
commit
4143180b42
8 changed files with 85 additions and 9 deletions
|
@ -4,11 +4,19 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||
|
||||
namespace Geekbot.net.Commands.Utils.Dice
|
||||
{
|
||||
public class Dice : ModuleBase
|
||||
{
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
|
||||
public Dice(IRandomNumberGenerator randomNumberGenerator)
|
||||
{
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command("dice", RunMode = RunMode.Async)]
|
||||
[Summary("Roll a dice.")]
|
||||
public async Task RollCommand([Remainder] [Summary("diceType")] string diceType = "1d20")
|
||||
|
@ -66,7 +74,7 @@ namespace Geekbot.net.Commands.Utils.Dice
|
|||
var results = new List<int>();
|
||||
for (var i = 0; i < dice.Times; i++)
|
||||
{
|
||||
var roll = new Random().Next(1, dice.Sides);
|
||||
var roll = _randomNumberGenerator.Next(1, dice.Sides);
|
||||
total += roll;
|
||||
results.Add(roll);
|
||||
if (roll == dice.Sides) extraText = "**Critical Hit!**";
|
||||
|
|
|
@ -9,6 +9,7 @@ using Geekbot.net.Lib.CommandPreconditions;
|
|||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Geekbot.net.Lib.Extensions;
|
||||
using Geekbot.net.Lib.Polyfills;
|
||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||
|
||||
namespace Geekbot.net.Commands.Utils.Quote
|
||||
{
|
||||
|
@ -18,11 +19,13 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
{
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
private readonly DatabaseContext _database;
|
||||
private readonly IRandomNumberGenerator _randomNumberGenerator;
|
||||
|
||||
public Quote(IErrorHandler errorHandler, DatabaseContext database)
|
||||
public Quote(IErrorHandler errorHandler, DatabaseContext database, IRandomNumberGenerator randomNumberGenerator)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_database = database;
|
||||
_randomNumberGenerator = randomNumberGenerator;
|
||||
}
|
||||
|
||||
[Command]
|
||||
|
@ -39,7 +42,7 @@ namespace Geekbot.net.Commands.Utils.Quote
|
|||
return;
|
||||
}
|
||||
|
||||
var random = new Random().Next(s.Count());
|
||||
var random = _randomNumberGenerator.Next(0, s.Count());
|
||||
var quote = s[random];
|
||||
|
||||
var embed = QuoteBuilder(quote);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue