Пример #1
0
 // rolling min or max will be rare, but rolling exactly between the two will be common
 public double GaussianRandom(double min, double max)
 {
     if (min > max)
     {
         Mathnv.Swap <double>(ref min, ref max);
     }
     min /= 3;
     max /= 3;
     return(Rand(min, max) + Rand(min, max) + Rand(min, max));;
 }
Пример #2
0
        // random normalized vector
        //from [ [min.x,min.y] , [max.x,max.y] ]
        public Vector3 RandVec3Normalized(float min, float max)
        {
            if (min > max)
            {
                Mathnv.Swap(ref min, ref max);
            }
            Vector3 vec = new Vector3(Rand(min, max), Rand(min, max), Rand(min, max)).normalized;

            vec.Normalize();
            return(vec);
        }
Пример #3
0
        public double Rand(double a, double b)
        {
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            double c = b - a;

            return(a + Randd() * c);
        }
Пример #4
0
        public float Rand(float a, float b)
        {
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            float c = b - a;

            return(a + Randf() * c);
        }
Пример #5
0
        public int Rand(int a, int b)
        {
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            int c = b - a;

            return(a + Randi() % c);
        }
Пример #6
0
        //random point in an area
        public Vector2 Rand(Vector2 a, Vector2 b)
        {
            if (a.x > b.x)
            {
                Mathnv.Swap(ref a.x, ref b.x);
            }
            if (a.y > b.y)
            {
                Mathnv.Swap(ref a.y, ref b.y);
            }

            float cx = b.x - a.x;
            float cy = b.y - a.y;

            return(new Vector2(a.x + Randf() * cx, a.y + Randf() * cy));
        }
Пример #7
0
        public uint Rand(uint a, uint b)
        {
            if (a == 0)
            {
                return(Rand(b));
            }
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }
            uint n = 2 * b;
            uint m = a + b;
            uint c = n % m;

            return(a + Rand() % c);
        }