Example #1
0
        private void RandRangeTest(IRandom Rand, int Iterations = 1000)
        {
            byte[] data;
            int x;
            long y;
            int min, max;
            min = Rand.Next(33);
            max = Rand.Next(34, 111);

            for (int i = 0; i < Iterations; i++)
                data = Rand.GetBytes(i * 10);

            for (int i = 1; i < Iterations; i++)
            {
                x = Rand.Next(i * min, i * max);
                if (x > i * max)
                    throw new Exception(Rand.Name + ":Next returned a value above of the expected range.");
                if (x < i * min)
                    throw new Exception(Rand.Name + ":Next returned a value below of the expected range.");
                y = Rand.NextLong(i * min, i * max);
                if (y > i * max)
                    throw new Exception(Rand.Name + ":NextLong returned a value above of the expected range.");
                if (y < i * min)
                    throw new Exception(Rand.Name + ":NextLong returned a value below of the expected range.");
            }
        }
Example #2
0
        public override HitResponse[] TotalRequest(HitRequest request)
        {
            var hitResponses = new List <HitResponse>();

            foreach (var fishData in request.FishDatas)
            {
                const int   MAX_WEPBET    = 10000;
                const int   MAX_WEPODDS   = 10000;
                const short MAX_TOTALHITS = 1000;
                const short MAX_FISHODDS  = 1000;
                const long  gateOffset    = 0x0fffffff;

                if (request.WeaponData.WeaponBet > MAX_WEPBET)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (request.WeaponData.WeaponOdds > MAX_WEPODDS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (request.WeaponData.TotalHits == 0 || request.WeaponData.TotalHits > MAX_TOTALHITS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (fishData.FishOdds == 0 || fishData.FishOdds > MAX_FISHODDS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                }
                else
                {
                    long gate = 1000;
                    gate *= gateOffset;
                    gate *= request.WeaponData.WeaponBet;
                    gate /= request.WeaponData.TotalHits;
                    gate /= fishData.FishOdds;
                    gate /= 1000;

                    if (gate > 0x0fffffff)
                    {
                        gate = 0x10000000;
                    }

                    var rValue = _Random.NextLong(0, long.MaxValue);

                    var value = rValue % 0x10000000;

                    if (value < gate)
                    {
                        hitResponses.Add(_Die(fishData, request.WeaponData));
                    }
                    else
                    {
                        hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    }
                }
            }

            return(hitResponses.ToArray());
        }
        /// <summary>
        /// Construct a random element over the field <c>gf2n</c>, using the specified source of randomness
        /// </summary>
        /// 
        /// <param name="Gf2n">The field</param>
        /// <param name="SecRnd">The source of randomness</param>
        public GF2nONBElement(GF2nONBField Gf2n, IRandom SecRnd)
        {
            mField = Gf2n;
            mDegree = mField.Degree;
            _mLength = Gf2n.GetONBLength();
            _mBit = Gf2n.GetONBBit();
            _mPol = new long[_mLength];

            if (_mLength > 1)
            {
                for (int j = 0; j < _mLength - 1; j++)
                    _mPol[j] = SecRnd.NextLong(); //ju next long?

                long last = SecRnd.Next();
                _mPol[_mLength - 1] = IntUtils.URShift(last, (MAXLONG - _mBit));
            }
            else
            {
                _mPol[0] = SecRnd.NextLong();
                _mPol[0] = IntUtils.URShift(_mPol[0], (MAXLONG - _mBit));
            }
        }