Use RandN properly and get rid of the iterations thingy for next double

This commit is contained in:
barelyprofessional
2026-02-19 20:55:55 -06:00
parent f1ab9cfcdd
commit 6967a81d73
2 changed files with 6 additions and 14 deletions

View File

@@ -92,14 +92,14 @@ public class Planes : ICommand
if (HOUSE_EDGE < 1) if (HOUSE_EDGE < 1)
{ {
if (Money.GetRandomDouble(gambler, 1) > (double)HOUSE_EDGE) if (Money.GetRandomDouble(gambler) > (double)HOUSE_EDGE)
{ {
_rigged = true; _rigged = true;
} }
} }
else else
{ {
if ((double)HOUSE_EDGE - Money.GetRandomDouble(gambler, 1) > 1) if ((double)HOUSE_EDGE - Money.GetRandomDouble(gambler) > 1)
{ {
_riggedWin = true; _riggedWin = true;
} }

View File

@@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using NLog; using NLog;
using RandN; using RandN;
using RandN.Compat; using RandN.Compat;
using RandN.Distributions;
namespace KfChatDotNetBot.Services; namespace KfChatDotNetBot.Services;
@@ -448,22 +449,13 @@ public static class Money
/// Get random number double [0, 1] /// Get random number double [0, 1]
/// </summary> /// </summary>
/// <param name="gambler">Gambler entity to reference their random seed</param> /// <param name="gambler">Gambler entity to reference their random seed</param>
/// <param name="iterations">Number of random number generator iterations to run before returning a result</param>
/// <returns>A random number based on the given parameters</returns> /// <returns>A random number based on the given parameters</returns>
/// <exception cref="ArgumentException"></exception> /// <exception cref="ArgumentException"></exception>
public static double GetRandomDouble(GamblerDbModel gambler, int iterations = 10) public static double GetRandomDouble(GamblerDbModel gambler)
{ {
var rng = StandardRng.Create(); var rng = StandardRng.Create();
var random = RandomShim.Create(rng); var dist = Uniform.New(0.0, 1.0);
var result = 0.0; return dist.Sample(rng);
var i = 0;
if (iterations <= 0) throw new ArgumentException("Iterations cannot be 0 or lower");
while (i < iterations)
{
i++;
result = random.NextDouble();
}
return result;
} }
/// <summary> /// <summary>