With come modifications to gurantee to have a number in the returned string.
private static String generateRandomCouponMethod3(int lengthOfString){ final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; final String numbers = "0123456789"; SecureRandom secureRandom = new SecureRandom(); StringBuilder sb = new StringBuilder(lengthOfString); for(int i = 0 ; i < lengthOfString ; ++i){ if(i%2 == 0){ sb.append(alphabet.charAt(secureRandom.nextInt(alphabet.length()))); }else{ sb.append(numbers.charAt(secureRandom.nextInt(numbers.length()))); } } return sb.toString();}