Ejemplo n.º 1
0
        public static T RandomOrDefault <T>(this IEnumerable <T> ts, Thirdparty.Random r)
        {
            if (!ts.Any())
            {
                return(default(T));
            }

            return(ts.Random(r));
        }
Ejemplo n.º 2
0
 // Returns a random offset in the range [-1..1,-1..1] with a separable
 // Gauss distribution with 'samples' values taken for each axis
 public static float2 Gauss2D(this Thirdparty.Random r, int samples)
 {
     return(new float2(Gauss1D(r, samples), Gauss1D(r, samples)));
 }
Ejemplo n.º 3
0
 public static float Gauss1D(this Thirdparty.Random r, int samples)
 {
     return(Graphics.Util.MakeArray(samples, _ => (float)r.NextDouble() * 2 - 1f)
            .Sum() / samples);
 }
Ejemplo n.º 4
0
 public static int2 ChooseRandomCell(this World w, Thirdparty.Random r)
 {
     return(new int2(
                r.Next(w.Map.Bounds.Left, w.Map.Bounds.Right),
                r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom)));
 }
Ejemplo n.º 5
0
 // Sampled a N-sample probability density function in the range [-1024..1024]
 // 1 sample produces a rectangular probability
 // 2 samples produces a triangular probability
 // ...
 // N samples approximates a true gaussian
 public static WRange FromPDF(Thirdparty.Random r, int samples)
 {
     return(new WRange(Exts.MakeArray(samples, _ => r.Next(-1024, 1024))
                       .Sum() / samples));
 }
Ejemplo n.º 6
0
 // Sampled a N-sample probability density function in the range [-1024..1024, -1024..1024]
 // 1 sample produces a rectangular probability
 // 2 samples produces a triangular probability
 // ...
 // N samples approximates a true gaussian
 public static WVec FromPDF(Thirdparty.Random r, int samples)
 {
     return(new WVec(WRange.FromPDF(r, samples), WRange.FromPDF(r, samples), WRange.Zero));
 }
Ejemplo n.º 7
0
        public static T Random <T>(this IEnumerable <T> ts, Thirdparty.Random r)
        {
            var xs = ts.ToArray();

            return(xs[r.Next(xs.Length)]);
        }
Ejemplo n.º 8
0
 public static float Gauss1D(this Thirdparty.Random r, int samples)
 {
     return(Exts.MakeArray(samples, _ => r.NextFloat() * 2 - 1f)
            .Sum() / samples);
 }