Howdy folks, was wondering if anyone could assist me in a better method for generating a alphanumeric sequence of 6 characters/digits. The method I am currently using gives me a random license plate number for a project I am working on. But I am unsatisfied with the results I am getting. Here is my current method, it works but like I said there has to be a better way of doing it.
Any help, suggestions or links to any relevant info is appreciated. Thanks.
Code:
public static String plate() { int x = 6; char[] plate = new char[x]; int c = 'A'; for(int p = 0; p < 6; p++) { int vehiclePlate = 0 + (int) (Math.random()* 6); switch(vehiclePlate) { case 0: c = '0' + (int)(Math.random() * 10); break; case 1: c = 'A' + (int)(Math.random() * 26); break; } plate[p] = (char)c; } return new String(plate); }
Comment