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. -
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);
-
}
-
Any help, suggestions or links to any relevant info is appreciated. Thanks.
5 8339
Umm, the method you have looks perfectly fine, so why not use it?
An alternative would be to create a character array holding the alphabet and numbers 0-9. Then you could build your string by adding random characters from the array.
Umm, the method you have looks perfectly fine, so why not use it?
An alternative would be to create a character array holding the alphabet and numbers 0-9. Then you could build your string by adding random characters from the array.
The results I am getting are:
AAAAAW
AAACCA
AAAAAA
AAAAXA
ETC..... they all are not exactly like that. And once every 20 times or so I get results that are satisfactory to me. I will try your alternate method. TY.
Ahh...you hadn't mentioned the part where it wasn't working very well ;)
The problem is, you generate random numbers between 0 and 5 to make a character, but you only test the cases 0 and 1. If you added the final 4 case statements, this would work perfectly well.
Ahh...you hadn't mentioned the part where it wasn't working very well ;)
The problem is, you generate random numbers between 0 and 5 to make a character, but you only test the cases 0 and 1. If you added the final 4 case statements, this would work perfectly well.
Wow that worked so well.
*astonished*
Ty Ganon.
No problems, glad to help!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Intaek LIM |
last post by:
generally, we use srand(time(0)) to generate random numbers.
i know why we use time(0), but i can not explain how it operates.
first, see example source below.
...
|
by: Joe |
last post by:
Hi,
I am building web in ASP.NET using VB.NET to code the pages. I want to generate random passwords for users. I know that password hashing is built right into the .NET Framework. I was...
|
by: randomcz |
last post by:
hi,
i need help with generating random numbers;
The task is to generate hundreds of random vectors, like
1,3,5,6,7
2,4,5,4,8
...
I used the current time as the random seed, but it turns...
|
by: Velhari |
last post by:
Hi,
I am a beginner. Please tell me, For generating Random Numbers, Initially why we are going for seed method.
And another question is that, I want to print unique random number how to print by...
|
by: avanti |
last post by:
Hi,
I need to generate random alphanumeric password strings for the users
in my application using Javascript. Are there any links that will have
pointers on the same?
Thanks,
Avanti
|
by: SammyB |
last post by:
These are some "random" thoughts about generating random numbers in Visual Basic.
Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator.
...
|
by: 9966 |
last post by:
Greetings,
This is my second post till now. Thanks for all the advice given to me for the first post.
Now I'm having problem with generating random numbers. I know if we want to generate a...
|
by: Krimp |
last post by:
I pulled this code from Vbasic.net or generating random passwords. I want to know how I can set up so that each time the page is refreshed a new password is generated without having to fill in the...
|
by: G Love |
last post by:
Hi, I am trying to modify some code in a toolbar I have for generating
random 'spam' entries on my forum.
I have managed to extract all the relevant files from the firefox .xpi
file and the .jar...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |