
/**
 * This class can be used to generate random letter sequences
 * 
 * @author Dave Reed 
 * @version 8/20/15
 */
public class SequenceGenerator {
	private String seqAlphabet;

	/**
	 * Constructs a sequence generator using the entire alphabet.
	 */
	public SequenceGenerator() {
		this.seqAlphabet = "abcdefghijklmnopqrstuvwxyz";
	}

	/**
	 * Constructor a sequence generator using a restricted alphabet
	 *   @param alphabet  a string of letters that can be used in the random sequences
	 */
	public SequenceGenerator(String alphabet) {
		this.seqAlphabet = alphabet;
	}
	
	/**
	 * Generates a random letter sequence of the specified length
	 *   @param  seqLength  the number of letters in the random sequence
	 *   @return the random letter sequence
	 */
	public String randomSequence(int seqLength) {
		String seq = "";
		for (int i = 0; i < seqLength; i++) {
		    int index = (int)(Math.random()*this.seqAlphabet.length());
		    seq = seq + this.seqAlphabet.charAt(index);
		}
		return seq;
	}
	
	/** 
	 * Displays a set number of random letter sequences of the specified length 
	 * @param numSequences the number of sequences to generate & display 
	 * @param seqLength the number of letters in the random sequences 
	 */ 
	public void displaySequences(int numSequences, int seqLength) { 
	    int wordsPerLine = 40 / seqLength; 
	    int sequencesSoFar = 0; 
	    while (sequencesSoFar < numSequences) { 
	        System.out.print(this.randomSequence(seqLength) + " "); 
	        sequencesSoFar = sequencesSoFar + 1; 
	        if (sequencesSoFar % wordsPerLine == 0 || sequencesSoFar == numSequences) { 
	            System.out.println(); 
	        } 
	    }
	} 
}
