Exemplo n.º 1
0
        public int Sample(IRNG random)
        {
            int index        = this.weights.IndexDistribution().Sample(random);
            var distribution = this.distributions[index];

            return(distribution.Sample(random));
        }
Exemplo n.º 2
0
        public static IList <int> GetIndicesShuffled <T>(this IList <T> list, IRNG random = null)
        {
            var indices = list.GetIndices().ToList();

            indices.Shuffle(random);

            return(indices);
        }
Exemplo n.º 3
0
        protected override IPathGenerator <IRNG> pathGenerator()
        {
            TimeGrid grid = this.timeGrid();
            IRNG     gen  = (IRNG) new  RNG().make_sequence_generator(grid.size() - 1, seed_);

            return(new PathGenerator <IRNG>(process_, grid,
                                            gen, brownianBridge_));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Chooses a random valid index for the <paramref name="list"/>.
        /// </summary>
        /// <typeparam name="T">Type of the elements in the enumerable.</typeparam>
        /// <param name="list">The enumerable to choose an index for.</param>
        /// <param name="random">Random number generator.</param>
        /// <returns>A valid index for the enumerable.</returns>
        public static int ChooseRandomIndex <T>(this IList <T> list, IRNG random = null)
        {
            var indexMax = list.Count;

            random ??= uRandom;

            return(list.Count > 0 ? random.Range(indexMax) : -1);
        }
Exemplo n.º 5
0
        protected override IPathGenerator <IRNG> pathGenerator()
        {
            int      dimensions = process_.factors();
            TimeGrid grid       = timeGrid();
            IRNG     generator  = (IRNG)FastActivator <RNG> .Create().make_sequence_generator(dimensions * (grid.size() - 1), seed_);

            return(new PathGenerator <IRNG>(process_, grid, generator, brownianBridge_));
        }
Exemplo n.º 6
0
 public static Vector2Int Vector2Int(this IRNG rng, int xMin, int xMax, int yMin, int yMax)
 {
     return(new Vector2Int
     {
         x = rng.Range(xMin, xMax),
         y = rng.Range(yMin, yMax)
     });
 }
Exemplo n.º 7
0
        public static ulong Next(this IRNG <ulong> rng, ulong min, ulong max)
        {
            if (min >= max)
            {
                throw new ArgumentOutOfRangeException(nameof(min));
            }

            return(min + Next(rng, max - min));
        }
Exemplo n.º 8
0
        public T Sample(IRNG random)
        {
            if (this.distribution == null)
            {
                this.distribution = this.BuildDistribution();
            }

            return(this.distribution.Sample(random));
        }
Exemplo n.º 9
0
 public YahtzeeDice(IRNG generator)
 {
     numberGenerator = generator;
     RollCount       = 0;
     dice            = new List <int>()
     {
         0, 0, 0, 0, 0
     };
 }
Exemplo n.º 10
0
        public static T ChooseAndExtract <T>(this IRNG random, IList <T> list)
        {
            var index = random.ChooseIndex(list);
            var item  = list[index];

            list.RemoveAt(index);

            return(item);
        }
Exemplo n.º 11
0
        public static uint Next(this IRNG <int> rng, uint min, uint max)
        {
            if (min >= max)
            {
                throw new ArgumentOutOfRangeException(nameof(min));
            }

            return(min + Next(rng, max - min));
        }
Exemplo n.º 12
0
        public static Vector2 Direction(this IRNG rng)
        {
            var vector = new Vector2
            {
                x = rng.Float(),
                y = rng.Float()
            };

            return(vector.normalized);
        }
Exemplo n.º 13
0
 private void RestoreState()
 {
     Group.SetIndex(_saveState.GroupIndex);
     Index = _saveState.Index;
     // Deep copy the data to be safe.
     // TO-DO: Optimize out deep copy
     HealVals    = new List <int>(_saveState.HealVals);
     _searchBuff = _saveState.SearchBuff.DeepClone();
     _searchRng  = _saveState.SearchRng.DeepClone();
 }
Exemplo n.º 14
0
        public static Vector2 InCircle(this IRNG random, Vector2 center, float radius)
        {
            var x = random.Range(-1f, 1f);
            var y = random.Range(-1f, 1f);

            var direction = new Vector2(x, y).normalized;
            var delta     = direction * random.Range(radius);

            return(center + delta);
        }
Exemplo n.º 15
0
        public static IEnumerable <int> RandomIndices <T>(this IList <T> list, IRNG random = null)
        {
            var maxIndex = list.Count;

            random ??= uRandom;

            while (true)
            {
                yield return(random.Range(maxIndex));
            }
        }
Exemplo n.º 16
0
        private static float StandardSample(IRNG random)
        {
            var sample1 = SCU.Distribution.Sample(random);
            var sample2 = SCU.Distribution.Sample(random);

            var log        = Mathf.Log(sample1);
            var squareRoot = Mathf.Sqrt(-2.0f * log);
            var cos        = Mathf.Cos(2.0f * Mathf.PI * sample2);

            return(squareRoot * cos);
        }
Exemplo n.º 17
0
        public HSVColor Generate(float hue, float value, IRNG random)
        {
            var saturation = random.Range(this.saturationRange);

            return(new HSVColor
            {
                Hue = hue,
                Saturation = saturation,
                Value = value
            });
        }
Exemplo n.º 18
0
        public T Draw(IRNG random)
        {
            if (this.drawPile.IsEmpty())
            {
                this.ShuffleInDiscard();
            }

            var index = this.drawPile.ChooseRandomIndex(random);
            var item  = this.DrawToDiscard(index);

            return(item);
        }
Exemplo n.º 19
0
        /// <summary>
        /// This method pre-rolls the RNG to the correct point
        /// so we can start matching on our cure list
        /// </summary>
        /// <param name="start">index of first cure</param>
        /// <param name="end">future RNGs to simulate</param>
        private void DisplayRNG(int start, int end, bool firstLoad = false)
        {
            mDispRng = InitializeRNG();
            //Consume RNG seeds before our desired index
            //This can take obscene amounts of time.
            for (int i = 0; i < start; i++)
            {
                mDispRng.genrand();
            }

            displayRNGHelper(start, end - start, firstLoad);
        }
Exemplo n.º 20
0
        public ColorScheme GenerateMonochromeScheme(float hue, IRNG random)
        {
            var colors = new HSVColor[this.colorCount];

            for (var index = 0; index < this.colorCount; index++)
            {
                var value = this.colorGenerator.ValueRange.RangeLerp((float)index / this.colorCount);
                colors[index] = this.colorGenerator.Generate(hue, value, random);
            }

            return(new ColorScheme(colors));
        }
Exemplo n.º 21
0
        private void Initialize()
        {
            Index = 0;
            _foundFirstRngPosition = false;
            Group.ResetIndex();
            _searchBuff = new CircularBuffer <uint>(SearchBufferSize);
            HealVals    = new List <int>();
            _searchRng  = InitializeRng();

            _searchRng.sgenrand();
            _searchBuff.Add(_searchRng.genrand());
        }
Exemplo n.º 22
0
        public FormMain()
        {
            InitializeComponent();

            cbSpellPow.SelectedIndex = 0;
            cbPlatform.SelectedIndex = 1;
            healVals  = new List <UInt32>();
            searchRNG = new RNG2002();
            dispRNG   = new RNG2002();
            toolStripStatusLabelPercent.Text  = "";
            toolStripStatusLabelProgress.Text = "";
        }
Exemplo n.º 23
0
        /// <summary>
        /// This method pre-rolls the RNG to the correct point
        /// so we can start matching on our cure list
        /// </summary>
        /// <param name="start">index of first cure</param>
        /// <param name="end">future RNGs to simulate</param>
        private void displayRNG(int start, int end)
        {
            IRNG dispRNG = InitializeRNG();

            //Consume RNG seeds before our desired index
            //This can take obscene amounts of time.
            for (int i = 0; i < start; i++)
            {
                dispRNG.genrand();
            }

            displayRNGHelper(dispRNG, start, end - start);
        }
Exemplo n.º 24
0
 /**
  *
  * @param width total width of the map, in cells
  * @param height total height of the map, in cells
  * @param roomWidth target width of each room, in cells; only counts the center floor area of a room
  * @param roomHeight target height of each room, in cells; only counts the center floor area of a room
  * @param random an IRNG to make random choices for connecting rooms
  * @param wallThickness how thick a wall between two rooms should be, in cells; 1 is minimum, and this usually
  *                      shouldn't be much more than roomWidth or roomHeight
  */
 public ConnectingGenerator(int width, int height, int roomWidth, int roomHeight, IRNG random, int wallThickness)
 {
     this.Width         = Math.Max(1, width);
     this.Height        = Math.Max(1, height);
     Region             = new Region(this.Width, this.Height);
     tempRegion         = new Region(this.Width, this.Height);
     this.RoomWidth     = Math.Max(1, roomWidth);
     this.RoomHeight    = Math.Max(1, roomHeight);
     this.WallThickness = Math.Max(1, wallThickness);
     Dungeon            = new Grid <char>(this.Width, this.Height, '#', '#');
     Environment        = new Grid <CellCategory>(this.Width, this.Height, CellCategory.Untouched, CellCategory.Untouched);
     Rng = random;
 }
Exemplo n.º 25
0
        protected override IPathGenerator <IRNG> controlPathGenerator()
        {
            int      dimensions = process_.factors();
            TimeGrid grid       = this.timeGrid();
            IRNG     generator  = (IRNG) new  RNG().make_sequence_generator(dimensions * (grid.size() - 1), this.seed_);
            HybridHestonHullWhiteProcess process = process_ as HybridHestonHullWhiteProcess;

            Utils.QL_REQUIRE(process != null, () => "invalid process");
            HybridHestonHullWhiteProcess cvProcess = new HybridHestonHullWhiteProcess(process.hestonProcess(),
                                                                                      process.hullWhiteProcess(), 0.0, process.discretization());

            return(new MultiPathGenerator <IRNG>(cvProcess, grid, generator, false));
        }
Exemplo n.º 26
0
        public RNGInfo(IRNG rng, int offset, Chest chestInfo1, Chest chestInfo2)
        {
            UInt32 prng1 = rng.PeekRand(offset);
            UInt32 prng2 = rng.PeekRand(offset + 1);
            UInt32 prng3 = rng.PeekRand(offset + 2);

            this.RawRNG         = prng1;
            this.StealNormal    = Steal.CheckSteal(prng1, prng2, prng3);
            this.StealWithCuffs = Steal.CheckStealCuffs(prng1, prng2, prng3);

            Chest1 = chestInfo1.CheckChest(prng1, prng2);
            Chest2 = chestInfo2.CheckChest(prng1, prng2);
        }
Exemplo n.º 27
0
        private void pathGenerator(UnderlyingInfo under)
        {
            ulong seed      = 1;
            int   timeSteps = 365;
            //
            int dimensions = this.processArr_.factors();

            double t = processArr_.time(maturity);

            TimeGrid grid = new TimeGrid(t, timeSteps);

            IRNG rndGenerator = (IRNG) new PseudoRandom().make_sequence_generator(dimensions * (grid.size() - 1), seed);

            this.pathGenerator_ = new MultiPathGenerator <IRNG>(this.processArr_, grid, rndGenerator, false);
        }
Exemplo n.º 28
0
        public T Sample(IRNG random)
        {
            var randomValue = random.Range(0, this.weightSum);

            foreach (var itemWeightPair in this.weights)
            {
                randomValue -= itemWeightPair.Value;
                if (randomValue <= 0)
                {
                    return(itemWeightPair.Key);
                }
            }

            return(this.weights.Keys.Last());
        }
Exemplo n.º 29
0
        public int GetSpawnFuture(IRNG rng, int offset = 0)
        {
            //TODO: Consider splitting ChestSpawn into its own class, and make its own future class if lack of caching turns out to be performance issue.
            //No need to implement future sync either because no cached future.
            //Or maybe just put a simple future calculation into the Chest Class?
            for (int i = 0; i < SearchDepth; i++)
            {
                if (this.Chest.CheckSpawn(rng, i + offset))
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 30
0
        public T Sample(IRNG random)
        {
            while (true)
            {
                var sample       = this.helper.Sample(random);
                var helperWeight = this.helper.Weight(sample) * this.factor;

                var weight = this.Weight(sample);

                if (Flip.Boolean(weight / helperWeight).Sample(random))
                {
                    return(sample);
                }
            }
        }
Exemplo n.º 31
0
        // by declaring these only once you get a huge performance boost
        // This method ensures that an RNG is only created once,
        // and not every time a Generate function is called
        protected void SelectRNG()
        {
            switch (frameType)
            {
                case FrameType.Gen4Normal:
                    mt = new MersenneTwister(0);
                    break;
                case FrameType.Gen4International:
                    mt = new MersenneTwister(0);
                    break;
                case FrameType.Method5Standard:
                    if ((maxResults + InitialFrame) < 221)
                    {
                        mt = new MersenneTwisterFast(0, (int) (maxResults + InitialFrame + 5));
                    }
                    else
                        mt = new MersenneTwister(0);

                    rngArray = new uint[maxResults + 9];
                    break;
                case FrameType.Method5CGear:
                    if ((maxResults + InitialFrame) < 219)
                    {
                        mt = new MersenneTwisterFast(0, (int) (maxResults + InitialFrame + 9));
                    }
                    else
                        mt = new MersenneTwister(0);

                    rngArray = new uint[maxResults + 8];
                    break;
                case FrameType.Method5Natures:
                    rngArray = new uint[maxResults + 9];
                    break;
            }
        }