public void TestRoulette3() { var l = BufUtils.Populate <float>(() => BufUtils.RandomInt(2) == 0 ? 0f : BufUtils.RandomFloat(100000), 10000); var r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k, 2f); int iszero = 0; for (int i = 0; i < 10000; ++i) { if (r.GetWeightedRandom() == 0f) { ++iszero; } } Assert.IsTrue(iszero > 10000 / 5); Assert.IsTrue(iszero < 10000 / 2); r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k, float.MaxValue); iszero = 0; for (int i = 0; i < 10000; ++i) { if (r.GetWeightedRandom() == 0f) { ++iszero; } } Assert.IsTrue(iszero < 4); }
public void TestRoulette2() { var l = BufUtils.RandomBytes(10000).AsEnumerable(); l = l.Concat(BufUtils.Populate <byte>(42, 10000)); var r = new I2PCore.Utils.RouletteSelection <byte, byte>(l, v => v, k => 1f); int is42 = 0; int samples = 10000; for (int i = 0; i < samples; ++i) { if (r.GetWeightedRandom(null) == 42) { ++is42; } } Assert.IsTrue(is42 > samples / 1000); }
public void TestRoulette3() { var populationcount = RouletteSelection <float, float> .IncludeTop; var samplecount = 50000; var l = BufUtils.Populate <float>(() => BufUtils.RandomInt(2) == 0 ? 0f : BufUtils.RandomFloat(100000), populationcount); var r = new I2PCore.Utils.RouletteSelection <float, float>(l, v => v, k => k); int iszero = 0; for (int i = 0; i < samplecount; ++i) { if (r.GetWeightedRandom(null) < float.Epsilon) { ++iszero; } } Assert.IsTrue(iszero > 0); Assert.IsTrue(iszero < samplecount / 2); }