﻿using UnityEngine;
using System.Collections.Generic;


public class Distribution  {

    public DistributioType distroType;
    public Dictionary<string, int> arguments = new Dictionary<string, int>();
	private int seed = 5;

    public Distribution(DistributioType distroType, Dictionary<string, int> arguments)
    {
        this.distroType = distroType;
        this.arguments = arguments;
    }

    public int generate()
    {
        switch (distroType)
        {

            case DistributioType.Random: return random_generator(arguments);//call normal generator 
            case DistributioType.Constant: return arguments["constant"];//call Constant generator 
            case DistributioType.Exponential: return genreate_expo();//call Exponential generator 
        }
        return 123;
    }
    
    private int random_generator(Dictionary<string, int> arguments)
    {
        return (int)Mathf.Floor(Random.Range((float)arguments["min"], (float)arguments["max"]));

    }


    public int normal_generator(Dictionary<string, int> arguments)
    {
		//UnityRandom urand = new UnityRandom(seed);

		//UnityRandom.Normalization.STDNORMAL, 5.0f
        float mean = (arguments["min"] + arguments["max"]) / 2;
        float sigma = (arguments["max"] - mean) / 3;
        return (int)Random.Range(mean, sigma);
        
    }   
    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
	public int genreate_expo()
	{
        /*UnityRandom urand = new UnityRandom(seed);
		float val = arguments ["min"] + (arguments ["max"] - arguments ["min"]) * urand.Exponential ((float)arguments ["landa"]);
		return (int)val;
        */
        
        float val = RandomFromDistribution.RandomRangeExponential(arguments["min"], arguments["max"], 0, RandomFromDistribution.Direction_e.Right);
        int new_val = Mathf.FloorToInt(val);

        return new_val;
	}
    
	/*
	public void testing()
	{
		this.arguments.Add("landa",5);
		this.arguments.Add("min",2);
		this.arguments.Add("max",6);
		int a = genreate_expo ();

		print (a);
	}
*/
}
