package edu.cornell.lassp.houle.RngPack;

/**
*   RandomShuffle shuffles the output of another random number generator
* to destroy sequential correlations.  To create a new RandomShuffle,
* pass it another RandomElement as follows:
*
* <PRE>
* RandomShuffle markov=new RandomShuffle(new RandomJava(),32)
* </PRE>
*
* This example creates a new RandomShuffle that shuffles the output
* of RandomJava (which uses the Math.random() generator built into Java)
* using a 32 number shuffle deck.
*
*
* <P>
* <A HREF="../src/edu/cornell/lassp/houle/RngPack/RandomShuffle.java" TARGET="edu.cornell.lassp.houle.source">
* Source code </A> is available.
*
* @author <A HREF="http://www.msc.cornell.edu/~houle" TARGET="edu.cornell.lassp.houle.author"> Paul Houle </A> (E-mail: <A HREF="mailto:ph18@cornell.edu">ph18@cornell.edu</A>)
* @version 0.9a
*/

public class RandomShuffle extends RandomElement {

  RandomElement generator;
  int decksize;
  double random,deck[]; 

/**
@param chaney a RandomElement to shuffle
@param ds the size of the shuffle deck
*/

  public RandomShuffle(RandomElement chaney,int ds) {
	int i;
	double duh;
	
	generator=chaney;
	decksize=ds;

	deck = new double[decksize];
	
	for(i=0;i<generator.choose(decksize);i++)
		duh=generator.raw();
		
	for(i=0;i<decksize;i++)
		deck[i]=generator.raw();

	random=generator.raw();
};

/**
@see RandomElement#raw
*/
public double raw() {

	int i;

	i=(int) Math.floor(decksize*random);
        random=deck[i];
        deck[i]=generator.raw();
	return random;
};
};


