438,032 Members | 811 Online Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

# Alpha Numeric Unique Random Number

 P: 16 Hi, Can I get a piece of code which can generate a 10 - 15 digit/character of uinque Random Number. The generated random number can contain both characters and digits. Regards, Kamalakar. Jan 29 '07 #1
5 Replies

 10K+ P: 13,264 Hi, Can I get a piece of code which can generate a 10 - 15 digit/character of uinque Random Number. The generated random number can contain both characters and digits. Regards, Kamalakar. A simple way of doing it is to use a char array containing all the characters that you want to use (including the numbers) and then pick a character at random until you reach anywhere between 10-15 characters. Do you still need more help on it? Jan 29 '07 #2

 P: 16 Can you give me a small example.......ie., piece of code Thanks & Regards, Kamal A simple way of doing it is to use a char array containing all the characters that you want to use (including the numbers) and then pick a character at random until you reach anywhere between 10-15 characters. Do you still need more help on it? Jan 29 '07 #3

 10K+ P: 13,264 Can you give me a small example.......ie., piece of code Thanks & Regards, Kamal You are a very lucky guy. Rarely in this forum do you get code when you have posted none yourself Expand|Select|Wrap|Line Numbers public class Test {     public static void main(String... args) {         char[] chars = new char;         int i = 0;         //This is for lower case characters only         for(char c = 'a'; c <= 'z';c++) {             chars[i++] = c;         }         i = 26;         for(char c = '0'; c <= '9';c++) {             chars[i++] = c;         }         int numberOfCodes = 0;         while (numberOfCodes < 10) {             int numChars = 10 + (int)(Math.random()*5.5);             String code = "";             for(i = 0; i < numChars; i++) {                 char c = chars[(int)(Math.random() * chars.length)];                 code = code + c;             }             System.out.println("Code is :"+code);              System.out.println("Length of code is :"+code.length());              System.out.println("***********************************");             numberOfCodes++;         }     } } Jan 29 '07 #4

 P: 16 Thanks a lot :) Regards, Kamal You are a very lucky guy. Rarely in this forum do you get code when you have posted none yourself Expand|Select|Wrap|Line Numbers public class Test {     public static void main(String... args) {         char[] chars = new char;         int i = 0;         //This is for lower case characters only         for(char c = 'a'; c <= 'z';c++) {             chars[i++] = c;         }         i = 26;         for(char c = '0'; c <= '9';c++) {             chars[i++] = c;         }         int numberOfCodes = 0;         while (numberOfCodes < 10) {             int numChars = 10 + (int)(Math.random()*5.5);             String code = "";             for(i = 0; i < numChars; i++) {                 char c = chars[(int)(Math.random() * chars.length)];                 code = code + c;             }             System.out.println("Code is :"+code);              System.out.println("Length of code is :"+code.length());              System.out.println("***********************************");             numberOfCodes++;         }     } } Jan 29 '07 #5

 10K+ P: 13,264 Thanks a lot :) Regards, Kamal Just remember to include your own code when asking next time. Jan 29 '07 #6 