• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySql Random Alphanumeric number

 
Amol Umrani
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What objective of the Sun Certified Java Programmers Exam does this relate to?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic