Java examples for java.lang:String Random
create Uppercase Random String
//package com.java2s; public class Main { public static final String ALL_UPPERCASE_VALUE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public static String createUppercaseRandom(int length) { if (length < 1) { throw new IllegalArgumentException( "length cannot be less than 1"); }// w w w. ja va2s . c om int vLen = ALL_UPPERCASE_VALUE.length(); String result = ""; for (int i = 0; i < length; i++) { double dr = Math.random() * vLen; int ir = (int) Math.floor(dr); result += ALL_UPPERCASE_VALUE.charAt(ir); } return result; } }