/// <summary> /// Produces a random stream predicated on a point source /// </summary> /// <param name="random">The point source</param> /// <typeparam name="T">The point type</typeparam> public static IEnumerable <T> Stream <T>(this IBoundPointSource <T> random) where T : struct { while (true) { yield return(random.Next()); } }
/// <summary> /// Takes a specified number of distinct points from a source /// </summary> /// <param name="random">The random source</param> /// <param name="count">The number of points to take</param> /// <typeparam name="T">The element type</typeparam> public static HashSet <T> TakeSet <T>(this IBoundPointSource <T> random, int count) where T : struct { var src = random.Stream(); var set = src.Take(count).ToHashSet(); while (set.Count < count) { set.AddRange(src.Take(count / 2)); } return(set); }
internal static int Next(this IBoundPointSource <ulong> random, int max) => max >= 0 ? (int)random.Next((ulong)max) : -(int)random.Next((ulong)(Int32.MaxValue + max));
/// <summary> /// Selects the next sequence of values from the source /// </summary> /// <param name="random">The random source</param> /// <param name="count">The number of values to select</param> /// <typeparam name="T">The value type</typeparam> public static IEnumerable <T> Take <T>(this IBoundPointSource <T> random, int count) where T : struct => random.Stream().Take(count);
/// <summary> /// Creates a polyrand rng from a point source /// </summary> /// <param name="rng">The source rng</param> public static IPolyrand ToPolyrand(this IBoundPointSource <ulong> source) => new Polyrand(source);
internal Polyrand(IBoundPointSource <ulong> Points) { this.Points = Points; this.Nav = default; }