Random Alphabet Maker : Random « Development « Android






Random Alphabet Maker

    
//package com.ou.android.game.common;

import java.util.ArrayList;

class RandomAlphabetMaker {

  private ArrayList<String> mList;
  int mCount;

  public RandomAlphabetMaker(int count) {
    mCount = count;
    init();
  }

  private void init() {
    mList = new ArrayList<String>();
    char a = 'A';
    for (int i = 0; i < mCount; i++) {
      char item = (char) (a + i);
      String s = Character.toString(item);
      mList.add(s);
    }
  }

  public ArrayList<String> getRandomList() {
    ArrayList<String> ret = new ArrayList<String>();
    if (mList.size() == 0) {
      init();
    }
    while (mList.size() > 0) {
      int index = (int) (Math.random() * 100) % mList.size();
      ret.add(mList.get(index));
      mList.remove(index);
    }
    return ret;
  }
}

   
    
    
    
  








Related examples in the same category

1.Next random Int
2.Random Xor Obfuscator
3.returns a random number among { 0 to count-1 }
4.Random Generator
5.Get Random Index