Optimization
This commit is contained in:
		
							parent
							
								
									b1dfeaec20
								
							
						
					
					
						commit
						43df57b1a1
					
				@ -6,7 +6,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class Exponential : IDistribution
 | 
					    public sealed class Exponential : IDistribution
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private double mean = 1;
 | 
					        private double mean = 1.0;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public IRandom Random { get; set; }
 | 
					        public IRandom Random { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,7 +15,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
            get => this.mean;
 | 
					            get => this.mean;
 | 
				
			||||||
            set
 | 
					            set
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if(value <= 0)
 | 
					                if(value <= 0.0)
 | 
				
			||||||
                    throw new ArgumentOutOfRangeException(message: "Mean must be greater than 0", null);
 | 
					                    throw new ArgumentOutOfRangeException(message: "Mean must be greater than 0", null);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                this.mean = value;
 | 
					                this.mean = value;
 | 
				
			||||||
@ -27,7 +27,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
            if (this.Random == null)
 | 
					            if (this.Random == null)
 | 
				
			||||||
                return 0.0;
 | 
					                return 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if(this.Mean == 1)
 | 
					            if(this.Mean == 1.0)
 | 
				
			||||||
                return -Math.Log(await this.Random.GetUniform(token));
 | 
					                return -Math.Log(await this.Random.GetUniform(token));
 | 
				
			||||||
            else
 | 
					            else
 | 
				
			||||||
                return this.Mean * -Math.Log(await this.Random.GetUniform(token));
 | 
					                return this.Mean * -Math.Log(await this.Random.GetUniform(token));
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,7 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class Gamma : IDistribution
 | 
					    public sealed class Gamma : IDistribution
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private double shape = 1;
 | 
					        private double shape = 1.0;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public IRandom Random { get; set; }
 | 
					        public IRandom Random { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -15,14 +15,14 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
            get => this.shape;
 | 
					            get => this.shape;
 | 
				
			||||||
            set
 | 
					            set
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if(value <= 0)
 | 
					                if(value <= 0.0)
 | 
				
			||||||
                    throw new ArgumentOutOfRangeException(message: "Shape must be greater than 0", null);
 | 
					                    throw new ArgumentOutOfRangeException(message: "Shape must be greater than 0", null);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                this.shape = value;
 | 
					                this.shape = value;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public double Scale { get; set; } = 1;
 | 
					        public double Scale { get; set; } = 1.0;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
					        public async ValueTask<double> GetDistributedValue(CancellationToken token)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
				
			|||||||
@ -6,18 +6,18 @@ namespace FastRng.Double.Distributions
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    public sealed class Normal : IDistribution
 | 
					    public sealed class Normal : IDistribution
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        private double standardDeviation = 1;
 | 
					        private double standardDeviation = 1.0;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        public IRandom Random { get; set; }
 | 
					        public IRandom Random { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public double Mean { get; set; } = 0;
 | 
					        public double Mean { get; set; } = 0.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public double StandardDeviation
 | 
					        public double StandardDeviation
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            get => this.standardDeviation;
 | 
					            get => this.standardDeviation;
 | 
				
			||||||
            set
 | 
					            set
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                if(value <= 0)
 | 
					                if(value <= 0.0)
 | 
				
			||||||
                    throw new ArgumentOutOfRangeException(message: "Standard deviation must be greater than 0", null);
 | 
					                    throw new ArgumentOutOfRangeException(message: "Standard deviation must be greater than 0", null);
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                this.standardDeviation = value;
 | 
					                this.standardDeviation = value;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user