Radom method
Java 2016
package com.giaima;
import java.security.SecureRandom;
public class RadomString {
static final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
static SecureRandom rnd = new SecureRandom();
String randomString(int len) {
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
sb.append(AB.charAt(rnd.nextInt(AB.length())));
}
return sb.toString();
}
//Test
public static void main(String[] args) {
RadomString r = new RadomString();
System.out.println(r.randomString(6));
}
}
0 nhận xét:
Post a Comment