public int Sample(IRNG random) { int index = this.weights.IndexDistribution().Sample(random); var distribution = this.distributions[index]; return(distribution.Sample(random)); }
public static IList <int> GetIndicesShuffled <T>(this IList <T> list, IRNG random = null) { var indices = list.GetIndices().ToList(); indices.Shuffle(random); return(indices); }
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_)); }
/// <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); }
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_)); }
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) }); }
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)); }
public T Sample(IRNG random) { if (this.distribution == null) { this.distribution = this.BuildDistribution(); } return(this.distribution.Sample(random)); }
public YahtzeeDice(IRNG generator) { numberGenerator = generator; RollCount = 0; dice = new List <int>() { 0, 0, 0, 0, 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); }
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)); }
public static Vector2 Direction(this IRNG rng) { var vector = new Vector2 { x = rng.Float(), y = rng.Float() }; return(vector.normalized); }
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(); }
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); }
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)); } }
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); }
public HSVColor Generate(float hue, float value, IRNG random) { var saturation = random.Range(this.saturationRange); return(new HSVColor { Hue = hue, Saturation = saturation, Value = value }); }
public T Draw(IRNG random) { if (this.drawPile.IsEmpty()) { this.ShuffleInDiscard(); } var index = this.drawPile.ChooseRandomIndex(random); var item = this.DrawToDiscard(index); return(item); }
/// <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); }
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)); }
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()); }
public FormMain() { InitializeComponent(); cbSpellPow.SelectedIndex = 0; cbPlatform.SelectedIndex = 1; healVals = new List <UInt32>(); searchRNG = new RNG2002(); dispRNG = new RNG2002(); toolStripStatusLabelPercent.Text = ""; toolStripStatusLabelProgress.Text = ""; }
/// <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); }
/** * * @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; }
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)); }
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); }
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); }
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()); }
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); }
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); } } }
// 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; } }