You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

38 lines
1.1 KiB

  1. package com.simple.utils;
  2. public class RandomUtils {
  3. private static String[] randomValues = new String[]{
  4. "0","1","2","3","4","5","6","7","8","9",
  5. "a","b","c","d","e","f","g","h","i","j",
  6. "k","l","m","n","u","t","s","o","x","v",
  7. "p","q","r","w","y","z"};
  8. private static String[] randomNums = new String[]{
  9. "0","1","2","3","4","5","6","7","8","9",
  10. };
  11. public static String getStr(int lenght) {
  12. StringBuffer str = new StringBuffer();
  13. for(int i = 0;i < lenght; i++) {
  14. Double number=Math.random()*(randomValues.length-1);
  15. str.append(randomValues[number.intValue()]);
  16. }
  17. return str.toString();
  18. }
  19. public static String getNum(int lenght) {
  20. StringBuffer str = new StringBuffer();
  21. for(int i = 0;i < lenght; i++) {
  22. Double number=Math.random()*(randomNums.length-1);
  23. str.append(randomNums[number.intValue()]);
  24. }
  25. return str.toString();
  26. }
  27. public static void main(String[] args) {
  28. System.out.println(getStr(32));
  29. }
  30. }