Esempio n. 1
0
 /// <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());
     }
 }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
 internal static int Next(this IBoundPointSource <ulong> random, int max)
 => max >= 0 ? (int)random.Next((ulong)max)
         : -(int)random.Next((ulong)(Int32.MaxValue + max));
Esempio n. 4
0
 /// <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);
Esempio n. 5
0
 /// <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);
Esempio n. 6
0
 internal Polyrand(IBoundPointSource <ulong> Points)
 {
     this.Points = Points;
     this.Nav    = default;
 }