1 文本格式
using System;
namespace Legalsoft.Truffer
{
public class Normaldev_BM : Ran
{
private double mu { get; set; }
private double sig { get; set; }
private double storedval { get; set; }
public Normaldev_BM(double mmu, double ssig, ulong i) : base(i)
{
this.mu = mmu;
this.sig = ssig;
this.storedval = 0.0;
}
public double dev()
{
double v1;
double v2;
double rsq;
double fac;
//if (storedval == 0.0)
if (Math.Abs(storedval) <= float.Epsilon)
{
do
{
v1 = 2.0 * doub() - 1.0;
v2 = 2.0 * doub() - 1.0;
rsq = v1 * v1 + v2 * v2;
} while (rsq >= 1.0 || Math.Abs(rsq) <= float.Epsilon);// (rsq >= 1.0 || rsq == 0.0);
fac = Math.Sqrt(-2.0 * Math.Log(rsq) / rsq);
storedval = v1 * fac;
return mu + sig * v2 * fac;
}
else
{
fac = storedval;
storedval = 0.0;
return mu + sig * fac;
}
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
public class Normaldev_BM : Ran
{
private double mu { get; set; }
private double sig { get; set; }
private double storedval { get; set; }
public Normaldev_BM(double mmu, double ssig, ulong i) : base(i)
{
this.mu = mmu;
this.sig = ssig;
this.storedval = 0.0;
}
public double dev()
{
double v1;
double v2;
double rsq;
double fac;
//if (storedval == 0.0)
if (Math.Abs(storedval) <= float.Epsilon)
{
do
{
v1 = 2.0 * doub() - 1.0;
v2 = 2.0 * doub() - 1.0;
rsq = v1 * v1 + v2 * v2;
} while (rsq >= 1.0 || Math.Abs(rsq) <= float.Epsilon);// (rsq >= 1.0 || rsq == 0.0);
fac = Math.Sqrt(-2.0 * Math.Log(rsq) / rsq);
storedval = v1 * fac;
return mu + sig * v2 * fac;
}
else
{
fac = storedval;
storedval = 0.0;
return mu + sig * fac;
}
}
}
}