content: package com.zzxhdzj.douban.api.base;
  
  import java.util.Random;
  
  /**
   * Created with IntelliJ IDEA.
   * User: yangning.roy
   * Date: 3/31/14
   * To change this template use File | Settings | File Templates.
   */
  public class RandomUtil {
      private static char[] characters = new char[]{
              'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
              '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
      };
  
      private static char[] alphas = new char[]{
              'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
      };
      private static char[] digitals = new char[]{
              '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
      };
  
      public static String getRandomString(int length) {
          StringBuilder sb = new StringBuilder();
          Random r = new Random();
          for (int i = 0; i < length; i++) {
              Integer index = r.nextInt(characters.length);
              sb.append(characters[index]);
          }
          return sb.toString();
      }
  }
  