Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.danielvaughan.wordgame;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
* Created by danielvaughan on 11/09/2014.
*/
public class LetterGenerator {
private List<Character> characterList = new ArrayList<Character>();
public LetterGenerator() {
initList();
}
private void initList() {
addLetters(new char[] {'K', 'J', 'X', 'Q', 'Z'}, 1);
addLetters(new char[] {'B', 'C', 'M', 'P', 'F', 'H', 'V', 'W', 'Y', '*'}, 2);
addLetters(new char[] {'G'}, 3);
addLetters(new char[] {'L', 'S', 'U', 'D'}, 4);
addLetters(new char[] {'N', 'R', 'T'}, 6);
addLetters(new char[] {'O'}, 8);
addLetters(new char[] {'A', 'I'}, 9);
addLetters(new char[] {'E'}, 12);
}
private void addLetters(char[] letters, int num)
{
for (char letter : letters) {
for (int i = 0; i < num; i++) {
characterList.add(letter);
}
}
}
public Character nextLetter() {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(100);
return characterList.get(randomInt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment