Optimization
This commit is contained in:
parent
45e8596588
commit
b1dfeaec20
@ -25,7 +25,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0.0;
|
||||||
|
|
||||||
if(this.Mean == 1)
|
if(this.Mean == 1)
|
||||||
return -Math.Log(await this.Random.GetUniform(token));
|
return -Math.Log(await this.Random.GetUniform(token));
|
||||||
|
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0.0;
|
||||||
|
|
||||||
// Implementation based on "A Simple Method for Generating Gamma Variables"
|
// Implementation based on "A Simple Method for Generating Gamma Variables"
|
||||||
// by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software
|
// by George Marsaglia and Wai Wan Tsang. ACM Transactions on Mathematical Software
|
||||||
|
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
|
|||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (this.Random == null)
|
if (this.Random == null)
|
||||||
return 0;
|
return 0.0;
|
||||||
|
|
||||||
var u1 = await this.Random.GetUniform(token);
|
var u1 = await this.Random.GetUniform(token);
|
||||||
var u2 = await this.Random.GetUniform(token);
|
var u2 = await this.Random.GetUniform(token);
|
||||||
|
@ -7,6 +7,6 @@ namespace FastRng.Double.Distributions
|
|||||||
{
|
{
|
||||||
public IRandom Random { get; set; }
|
public IRandom Random { get; set; }
|
||||||
|
|
||||||
public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0 : await this.Random.GetUniform(token);
|
public async ValueTask<double> GetDistributedValue(CancellationToken token = default) => this.Random == null ? 0.0 : await this.Random.GetUniform(token);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user