/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qsim.rng;

import java.util.ArrayList;
import qsim.distributions.PseudoHypoExpDist;
import umontreal.iro.lecuyer.probdist.Distribution;
import umontreal.iro.lecuyer.probdist.ExponentialDist;
import umontreal.iro.lecuyer.randvar.RandomVariateGen;
import umontreal.iro.lecuyer.rng.MRG32k3a;
import umontreal.iro.lecuyer.rng.RandomStream;

/**
 *
 * @author joe
 */
public class HypoExpRandomVariateGen extends RandomVariateGen {

    private ArrayList<RandomVariateGen> rngList;
    public int k;

    public HypoExpRandomVariateGen(RandomStream s, Distribution dist) {
        super(s, dist);
        if (this.dist instanceof PseudoHypoExpDist) {
            k = dist.getParams().length;
            PseudoHypoExpDist heDist = (PseudoHypoExpDist) this.dist;
            rngList = new ArrayList<RandomVariateGen>();
            for (int i = 0; i < k; i++) {
                
                long[] seed = {Math.round(Math.random() * 100000), Math.round(Math.random() * 100000), Math.round(Math.random() * 100000),
                    Math.round(Math.random() * 100000), Math.round(Math.random() * 100000), Math.round(Math.random() * 100000)
                };
                
                MRG32k3a rngStream = new MRG32k3a();
                rngStream.setSeed(seed);
                
                rngList.add(new RandomVariateGen(rngStream, heDist.getExpDist(i)));
            }
        }
    }

    @Override
    public void nextArrayOfDouble(double[] v, int start, int n) {
    }

    @Override
    public double nextDouble() {
        if (this.dist instanceof PseudoHypoExpDist && k != 0) {
            
            double rnmb = 0.0;
            for (int i=0; i<this.rngList.size(); i++){
                rnmb += this.rngList.get(i).nextDouble();
            }
            return rnmb;
        }
        return 0;
    }
}
