コード例 #1
0
        public void RandomShuffle <T>(List <T> elements)
        {
            int n = elements.Count();

            for (int i = n - 1; i > 0; --i)
            {
                Mathnv.Swap(elements, i, Rand(i + 1));
            }
        }
コード例 #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
 // 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)
     {
         return(min);
     }
     if (min > max)
     {
         Mathnv.Swap <double>(ref min, ref max);
     }
     min /= 3;
     max /= 3;
     return(Rand(min, max) + Rand(min, max) + Rand(min, max));;
 }
コード例 #4
0
        public double Rand(double a, double b)
        {
            if (a == b)
            {
                return(a);
            }
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            double c = b - a;

            return(a + Randd() * c);
        }
コード例 #5
0
        public float Rand(float a, float b)
        {
            if (a == b)
            {
                return(a);
            }
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            float c = b - a;

            return(a + Randf() * c);
        }
コード例 #6
0
        public int Rand(int a, int b)
        {
            if (a == b)
            {
                return(a);
            }
            if (a > b)
            {
                Mathnv.Swap(ref a, ref b);
            }

            int c = b - a;

            return(a + Randi() % c);
        }
コード例 #7
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));
        }
コード例 #8
0
        public uint Rand(uint a, uint b)
        {
            if (a == b)
            {
                return(a);
            }
            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);
        }