Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

MySql Random Alphanumeric number

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What objective of the Sun Certified Java Programmers Exam does this relate to?
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 4323
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Happily living in the valley of the dried frogs with a few tiny ads.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic