コード例 #1
0
ファイル: GameBalance.cs プロジェクト: OlegGelezcov/neb
        public static float StandardNormalRandomNumber()
        {
            float u = Rand.Float01();
            float v = Rand.Float01();
            float x = Mathf.Sqrt(-2f * Mathf.Log(u)) * Mathf.Cos(2f * Mathf.PI * v);

            return(x);
        }
コード例 #2
0
        public static int[] GenerateNumbers(int numberCount, int numberSum)
        {
            if (numberCount == 0)
            {
                numberCount = 2;
            }

            if (numberCount == 1)
            {
                return new int[] { numberSum }
            }
            ;

            int[] result = new int[numberCount];
            int   points = numberSum;

            while (points > 0)
            {
                for (int i = 0; i < result.Length; i++)
                {
                    if (Rand.Float01() < 0.5f && points > 0)
                    {
                        result[i] += 1;
                        points--;
                    }
                }
            }

            //int[] generatedPoint = new int[numberCount - 1];
            //for (int i = 0; i < generatedPoint.Length; i++)
            //{
            //    generatedPoint[i] = Rand.Int(numberSum);
            //}

            //Array.Sort(generatedPoint);

            //int[] result = new int[numberCount];
            //for (int i = 0; i < numberCount; i++)
            //{
            //    if (i == 0)
            //    {
            //        result[i] = generatedPoint[0] - 0;
            //    }
            //    else if (i > 0 && i < generatedPoint.Length)
            //        result[i] = generatedPoint[i] - generatedPoint[i - 1];
            //    else
            //        result[i] = numberSum - generatedPoint[generatedPoint.Length - 1];
            //}
            return(result);
        }