aspose file tools*
The moose likes JDBC and the fly likes MySql Random Alphanumeric number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySql Random Alphanumeric number" Watch "MySql Random Alphanumeric number" New topic
Author

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
Rancher

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
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
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: 3704
    
    5

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 ]

My Blog: Down Home Country Coding with Scott Selikoff
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MySql Random Alphanumeric number