English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hey,

Im trying to make a program but i need a litte help, The program im trying to make is like a CD code Generator.
I world like it to be, 4 numbers and 12 letters.
E.G

1QAE-9RED-6YCE-4KJB

Now i been trying to make this program ( and its in Java ) but i can make a Random Number Generator. ( from 0 - 9 )

but i dont no how to make a Random Letter Generator from A - Z

so if you can give me some tips or what i need to import.* or if you can make a small code up that can make Random Letters what would be great ( but not in swing / GUI coz that up be too much work for you :P )

or if you know of some link(s)

thank you

2007-03-21 23:53:58 · 4 answers · asked by lonewolfy92 1 in Computers & Internet Programming & Design

4 answers

It's quite easy create a new array:

String[] letters= {"A", "B", "C".....etc}

Then use a random number generator to create a number between 0 and 25 (because arrays start indexing at 0) then
for example, store that number in an int (lets call it num) then do

letters[num] - this will give you the num'th entry into the array which will be a letter from a-z

2007-03-22 00:51:06 · answer #1 · answered by Anonymous · 0 0

if you think about it, ascii letters are no different to numbers - they can be represented with ints. All you have to ensure is your random number generator can produce a valid ascii char code when you want a letter, then do a conversion. Easy, and extensible.

2007-03-22 02:56:44 · answer #2 · answered by ross_killip 2 · 0 0

won't write the code for you yet generate a random type from a million to 6, use a string function (lstring working example) to pick the x character from the left. do thid 4 cases.

2016-10-19 08:06:15 · answer #3 · answered by ? 4 · 0 0

http://www.java-tips.org/java-se-tips/java.util/how-to-generate-a-random-number-3.html

2007-03-22 00:47:42 · answer #4 · answered by ROY L 6 · 0 0

fedest.com, questions and answers