/// <summary>
    /// Pick a random winner in the lottery.
    /// </summary>
    /// <param name="pickedIndex">The index of the picked element</param>
    /// <returns></returns>
    public T Pick(ref FixRandom random, out int pickedIndex)
    {
        pickedIndex = -1;

        if (_list.Length <= 0)
        {
            Log.Error("No lottery item to pick from. Add some before picking.");
            return(default(T));
        }

        fix ticket        = random.NextFix(0, TotalWeight);
        fix currentWeight = 0;

        for (pickedIndex = 0; pickedIndex < _list.Length; pickedIndex++)
        {
            currentWeight += _list[pickedIndex].Weight;
            if (ticket < currentWeight)
            {
                return(this[pickedIndex]);
            }
        }

        Log.Error("Error in lottery.");
        return(default(T));
    }
Beispiel #2
0
    public WorldModuleTickRandom(uint tickId, uint seed)
    {
        _randomFromTick = new FixRandom(BitConverterX.UInt32ToInt32(((tickId + 1) * 99877) + seed));

        uint mod = tickId % 7;

        for (int i = 0; i < mod; i++)
        {
            _randomFromTick.NextUInt();
        }
    }
 /// <summary>
 /// Pick a random winner in the lottery.
 /// </summary>
 public T Pick(ref FixRandom fixRandom)
 {
     return(Pick(ref fixRandom, out _));
 }
Beispiel #4
0
 public fix GetNext(ref FixRandom random)
 {
     return(random.NextPlateau(BaseValue - Variation, BaseValue + Variation, DistributionPlateau));
 }