1 文本格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// Cauchy deviates
/// </summary>
public class Cauchydev : Ran
{
private double mu { get; set; }
private double sig { get; set; }
public Cauchydev(double mmu, double ssig, ulong i) : base(i)
{
this.mu = mmu;
this.sig = ssig;
}
public double dev()
{
double v1;
double v2;
do
{
v1 = 2.0 * doub() - 1.0;
v2 = doub();
} while (Globals.SQR(v1) + Globals.SQR(v2) >= 1.0 || v2 == 0.0);
return mu + sig * v1 / v2;
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// Cauchy deviates
/// </summary>
public class Cauchydev : Ran
{
private double mu { get; set; }
private double sig { get; set; }
public Cauchydev(double mmu, double ssig, ulong i) : base(i)
{
this.mu = mmu;
this.sig = ssig;
}
public double dev()
{
double v1;
double v2;
do
{
v1 = 2.0 * doub() - 1.0;
v2 = doub();
} while (Globals.SQR(v1) + Globals.SQR(v2) >= 1.0 || v2 == 0.0);
return mu + sig * v1 / v2;
}
}
}