jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes MySql Random Alphanumeric number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySql Random Alphanumeric number" Watch "MySql Random Alphanumeric number" New topic

MySql Random Alphanumeric number

Amol Umrani
Ranch Hand

Joined: Jun 21, 2006
Posts: 36
How can we generate Random alphanumeric number in mysql?
we can generate random number using rand()?
But i dont know about how to generate alphanumeric number?
Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
What objective of the Sun Certified Java Programmers Exam does this relate to?

SCWCD: Online Course, 50,000+ words and 200+ questions
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yup, off we go to somewhere else...
But where? Let's try JDBC... it's not really JDBC but it's nearer to MySQL than SCJP is.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

Lol, I'm not sure what question I'd be responding to but here goes...

Many random number generators generate a float from 0 to 1. Java is friendly in that it gives you some other features like random generating integers, longs, etc, but all you really need is a float from 0 to 1. Lets call this number SuperR.

Let's say you want a random number from 200-1000. Well, the range of that number is 800 (1000-200) so what you really want is 200 + (some number from 0-800). So you take the range, 800, multiply it by SuperR, (think of this as percentage, you want 0-100% of 800), and then add 200. In the case of integers, then just call floor/top to round the number to the nearest integer.

Now, in the case of alphanumerics, the first question is "what do you consider alpha numerics?" such as do you consider letters with accent marks, spaces, commas, ASCII characters, or other things alphanumerics. Once you decide that you can then make a character array out of them lets say that has 50 elements. Put one character in each spot in the array. Next, generate a random number from 0-49 (as previously described) and use that as an index into the array.

As for mysql... any solution would be database-dependent so you should do the coding in java.
[ July 11, 2006: Message edited by: Scott Selikoff ]

[OCA 8 Book] [Blog]
I agree. Here's the link: http://aspose.com/file-tools
subject: MySql Random Alphanumeric number
It's not a secret anymore!