乱数を作成してから、見つけたこのボックス ミュラー アルゴリズムを使用しようとしています。私が直面している問題は、System.Random 値を使用してあらゆる種類の数学演算を行うことです。平方根やログを取得したり、浮動小数点値と混ぜたりすることはできません。このランダム分布のコードは次のとおりです。数日間考えましたが、何も思いつきません。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Random rand1 = new Random();
Console.WriteLine("999 Doubles1.");
for (int ctr = 0; ctr <= 999; ctr++)
Console.Write("{0,8:N3}", rand1.NextDouble());
Console.WriteLine();
Random rand2 = new Random();
Console.WriteLine("999 Doubles2.");
for (int ctr = 0; ctr <= 999; ctr++)
Console.Write("{0,8:N3}", rand2.NextDouble());
Console.WriteLine();
float mu = .75F;
float sigma = .1F;
float z1 = Math.Sqrt(-2 * Math.Log(rand1)) * Math.Sin(2 * Math.PI * rand2);
float z2 = Math.Sqrt(-2 * Math.Log(rand1)) * Math.Cos(2 * Math.PI * rand2);
float x1 = mu + z1 * sigma;
float x2 = mu + z2 * sigma;
}
}
}