Generate 8 Digit Alpha Numeric Unique Random String Using Java,
Generate Six Digit Unique Random String Using Java,
8 Digit Random String Generete with Java,
Generate Unique Random String in Java with Example
Java Code: Java Generate Unique Random Alphanumeric String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import java.util.Random; import java.util.Scanner; public class JavaExamples2 { public static String getRandom(int digits) { Random rand = new Random(); //instance of random class String total_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; String randomString = ""; for (int i = 0; i < digits; i++) { int index = rand.nextInt(total_characters.length()-1); randomString += total_characters.charAt(index); } return randomString; } public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.println("Java Generate Random String Fixed Length"); System.out.printf("Random String: %s\n",getRandom(8)); } } |