×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: digas
Added: Sep 26, 2014 2:53 PM
Views: 1814
Tags: commons-lang
  1.  
  2. <dependency>
  3.     <groupId>commons-lang</groupId>
  4.     <artifactId>commons-lang</artifactId>
  5.     <version>20030203.000129</version>
  6. </dependency>
  7. The class we are interested in is RandomStringUtils. Listed below are some functions you may find useful.
  8.  
  9. Generate and print a random string of length 5 from all characters available
  10.  
  11. System.out.println(RandomStringUtils.random(5));
  12. Generate and print random string of length 10 from upper and lower case alphabets
  13.  
  14. System.out.println(RandomStringUtils.randomAlphabetic(10));
  15. Generate and print a random number of length 12
  16.  
  17. System.out.println(RandomStringUtils.randomNumeric(12));
  18. Generate and print a random string of length 5 using only a, b, c and d characters
  19.  
  20. System.out.println(RandomStringUtils.random(10,new char[]{'a','b','c','d'}));