Random alphanumeric string

Hi,
I need one function which generates a Random alphanumeric string which I want to use as a primary key value. So it must be unique too.
Something similar to sys_guid in oracle, However I need length of the string fixed to be 6. sys_guid is not helpful as it generates 32 characters long string.
Can somebody help please?
Thanks in advance!
RK

You can find many examples by doing a search on this forum:
Alphanumeric sequence number generator

Similar Messages

  • Generate random alphanumeric string as pk

    Hallo,
    I want to generate a random and unique alphanumeric string (4-digit).
    Uniqueness is very important, because it will be used as primary key.
    Is this supported by oracle 10?

    You can try the sys_guid function:
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Linux IA64: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL> select sys_guid() from dual;
    SYS_GUID()
    439F46B40AAAFB59E04014ACAE650DC1
    SQL> create table guid_tbl(str varchar2(300), constraint guid_tbl_pk primary key
    (str));
    Table created.
    SQL> begin
      2  for i in 1..1000 loop
      3     insert into guid_tbl(str) values(sys_guid());
      4  end loop;
      5  end;
      6  /
    PL/SQL procedure successfully completed.
    SQL> select count(*) from guid_tbl;
      COUNT(*)
          1000
    SQL>Amiel

  • Random alphanumeric anyone?

    Hi guys. I was wondering how i can generate random alphnumeric strings like for example: f81d4fae-7dec-11d0-a765-00a0c91e6bf6. Is there a random function ready in java and if es how can it be used with alphanumeric characters. Any opinions would be appriciated.

    There are 62 alphanumeric characters
    0 to 9 = ascii 48 to 57:
    65 to 90 = ascii A to Z:
    97 to 122 = ascii a to z:
    1. Generate (however many) random numbers from 0 to 61
    2. If the number generated ... thrfr <in psuedocode>
    if(num < 10) myStr +=(char)num + 48;
    else if(num > 35)myStr +=(char)num + 62;
    else myStr +=(char)num + 55;
    3. Sorted!

  • Generating alphanumeric string

    Hi,
    I'm new to java programming and
    I was wondering if anyone could help.
    I need to generate an alphanumeric string
    consisting of one uppercase letter and 4 digits.
    Ant help gratefully received

    import java.util.Random;
    public class Test {
      private static final char[] uppercaseLetters = { 'A', 'B', 'C', 'D', 'E', 'F',
        'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
      public Test() {
        final StringBuffer sb = new StringBuffer();
        sb.append(uppercaseLetters[(int)(Math.random() * uppercaseLetters.length)]);
        for (int i = 0; i < 4; i++) sb.append((int)(Math.random() * 10));
        System.out.println(sb);
      public static void main(String[] args) {
        new Test();
    }

  • Sorting randomly genareted string in alphapetic order

    import java.util.*;
    public class test {
        public static char[] chars;
        public static Random random;
        static {
            chars = new char[26];//taking caracters from asci table
            for (int i = 0; i < 26; i ++) {
                chars[i] = (char) (97 + i);           
            random = new Random ();
        public static void main (String[] args) { //printing random characters
                for (int i = 1; i <= 10; i++ ) {                                                                          
                System.out.println(randomString(20)); 
        private static String randomString (int length) { //generating random
            char[] array = new char[length];
            for (int i = 0; i < length; i ++) {
                array[i] = chars[random.nextInt (chars.length)];
        return new String (array);
        i have this code.i found that in the forums and modified it a bit.but i have still problems to sort randomly genareted strings in alphabetic order.i have a method to do it.but i couldn't implement it correctly.the way that i try to sort them is
    void sort(String[] a) {
      for (int i=0; i<a.length-1; i++) {
         for (int j=i+1; j<a.length; j++) {
            if (a.compareTo(a[j]) > 0) {
    String temp=a[j];
    a[j]=a[i];
    a[i]=temp;
    thats a method i try to use but i couldn't put it in a correct place in the code and couldn't call him.always it gives error.pls help this unexprienced java user...

    Hard to understand your problems, because you're too vague. At one point you mention you don't know where to put your method, at another you say you don't know how to call your method. If that is the case (which seems unlikely but oh well) here's an example.
    public class Testing9 {
         public Testing9() { // constructor
              String basicString = "BasicExample";
              String sortedString = mySortMethod(basicString); // call mySortMethod passing the string
              System.out.println("sortedString = " + sortedString);
         public static void main(String[] args) { // main method starts app
              Testing9 app = new Testing9(); // calls constructor
         public String mySortMethod(String s) { // put the method here cause I feel like it
              String sortedString = "";
              // do your own work here to sort, etc....
              return sortedString;
    }

  • Finding the smallest letter in a single alphanumeric string

    How do I find the smallest letter in a single alphanumeric input?
    I already wrote and successfully tested the code that takes an alphanumeric string as input, separates the number from the alphabet, and creates a new alphabetic string. However, I'm unsuccesful in writting the code to find the smallest letter within the alphabetic string. I am almost certain that the easy answer is Arrays.sort, but I unsuccesfully tried writing the code to place the alphabetic string into an array. I researched compareTo, but I do not have another object to compare?! Any suggetsions?

    Ahh flaimbait - I'm sure I'll get criticized for this... but - while we are talking about time-to-market, etc...:
    The most important issue in development is to make sure that you understand the project requirements. The requirements in this situation were:
    Find the smallest character in a string.
    Given that, then any developer that goes through the trouble of looking up the sort APIs, etc... is not helping themselves - all they really needed to do was to write one line of code (as xxxx graciously posted):
    for (int x=0; x<foo.length(); x++) if (foo.charAt(i)<low) low=foo.charAt(x);I absolutely guarantee that any Java programmer could write the above faster than they could figure out how to split a string appart by characters, look up the arraysort API, etc...
    The arraysort functions are EXTREMELY efficient, and I would never suggest that someone re-implement them. The point here is that just because you've got a wrecking ball available, you can still use a hammer to drive a nail.

  • HOW TO GENERATE RANDOM MEANINGFUL STRINGS ?

    Friends,
    How do I generate random meningfull strings ? I know how to generate strings randomly but I want to generate meaningfull names. The length is not important. Please help me in this matter as I have to implement this soon.
    Thanks in advance
    Ankit.

    Thanks for reply,
    I want to generate any string randomly and also want to make sure that it is meaningfull name. I can use Random(0n class to generate random number then convert according to ascii table to char and concat these generated chars to have string but then it is not meaningfull string, it could be anything. I want the string to be meaningfull too.(any word or name in english language). I don't want to pick up already generated word or names from list randomly(i think this is what you are thinking)

  • Produce random alphanumeric characters: dukes available

    Time for another duke giveaway
    On Saturday 6th March, approx 8.00PM (GMT) the following program will be run;-
    CodeMaker.javapublic class CodeMaker{
       public static void main(String []params){
          StringBuffer  sb = new StringBuffer();
          java.util.Random r = new java.util.Random();
          for(char c='A'; c<='Z'; c++) sb.append(c);
          for(char c='a'; c<='z'; c++) sb.append(c);
          for(int i=0; i<=10; i++) sb.append(i);
          for(int i=0; i<8; i++) System.out.print(sb.charAt(r.nextInt(sb.length()) ) );
    ALL ARE WELCOME TO GUESS THE OUTCOME OF THIS PROGRAM AND EARN FREE DUKES!
    - simply add to this thread with your guess of the 8 alphanumeric characters.
    - the more characters you guess right the more you earn.
    - only one guess permitted per contestant (schizoids such as the Scarlet Pimpernel excl.)
    - any other rules may or may not be made by me at any time (after all it is my game so ner-ner-nee-ner-ner)
    - that's all I can think of for the moment, good luck t'y'all.
    The points system awarded will be determined by the following program;-
    CodeScorer.javapublic class CodeScorer{
       public static void main(String []params){
          String luckyDukeWinner = params[0];
          String codeToCrack = params[1];
          String luckyDukeWinnerGuess = params[2];
          new CodeScorer(luckyDukeWinner, codeToCrack, luckyDukeWinnerGuess);
       private CodeScorer(String name, String code, String guess){
          int same = calcSame(code, guess, 0);
          int correct = calcCorrect(code, guess, 0);
          System.out.println("Number of letters correct = "+same);
          System.out.println("Number of letters exactly correct = "+correct);
          System.out.println("Dukes earned by "+name+": "+calcScore(same, correct));
       private int calcCorrect(String code, String guess, int tally){
          for (int i=0; i< code.length(); i++)
             if(guess.charAt(i) == code.charAt(i)) tally++;
          return tally;
       private int calcSame(String code, String guess, int tally){
          StringBuffer buf = new StringBuffer(code);
          for (int i=0; i< buf.length(); i++){
             for (int j=0; j< buf.length(); j++)
                if (guess.charAt(i) == buf.charAt(j)){
                   tally++;
                   buf.replace(j, j+1,"~");
          return tally;
       private int calcScore(int same, int correct){
          return (same>1 && correct>1)? (int)((correct*4)*(Math.pow(same,2))):(int)((correct*4)+(Math.pow(same,2)));
    }

    I thought this
    for(int i=0; i<=10; i++) sb.append(i);
    would do this
    for(int i=0; i<=10; i++) sb.append((char)i);
    I'm so humilitated....All punters may assume henceforth that line 7 char 22 is herewith removed (I'm humiliated too)

  • Regular Expression Pattern maching class to Validate Alphanumeric String

    Hi
    MY DB version is Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    I wanted to use the pattern maching classes given by oracle to check whether a given input string is alphanumeric or not.
    Oracle 10g documentation says about the classes like [:digit:], [:alnum:] and many others.
    http://www.dba-oracle.com/t_regular_expressions.htm
    However these classes seems not to be working with my DB version.
    Can someone tell me the DB version in which these classes works ?
    Below is the code I am using to validate a input string.
    SQL> CREATE OR REPLACE FUNCTION fn_is_alphanumeric
      2  (
      3     pi_value             IN       VARCHAR2
      4  )
      5  RETURN VARCHAR2
      6  IS
      7     lv_length   NUMBER;
      8  BEGIN
      9     lv_length := length(pi_value);
    10     IF ( REGEXP_LIKE(pi_value,'[:alnum:]{'||lv_length||'}')) THEN
    11        RETURN 'TRUE';
    12     ELSE
    13        RETURN 'FALSE';
    14     END IF;
    15  END fn_is_alphanumeric;
    16  /
    Function created.
    SQL>
    SQL>
    SQL> SELECT fn_is_alphanumeric('abc123') alpha FROM DUAL;
    ALPHA
    FALSE
    SQL>
    SQL>
    SQL> CREATE OR REPLACE FUNCTION fn_is_alphanumeric
      2  (
      3     pi_value             IN       VARCHAR2
      4  )
      5  RETURN VARCHAR2
      6  IS
      7     lv_length   NUMBER;
      8  BEGIN
      9     lv_length := length(pi_value);
    10     IF ( REGEXP_LIKE(pi_value,'[A-z0-9]{'||lv_length||'}')) THEN
    11        RETURN 'TRUE';
    12     ELSE
    13        RETURN 'FALSE';
    14     END IF;
    15  END fn_is_alphanumeric;
    16  /
    Function created.
    SQL> SELECT fn_is_alphanumeric('abc123') alpha FROM DUAL;
    ALPHA
    TRUE

    Character classes are working fine with regexp engine in your database version - simply change your function definition to:
    CREATE OR REPLACE FUNCTION fn_is_alphanumeric
       pi_value             IN       VARCHAR2
    RETURN VARCHAR2
    IS
       lv_length   NUMBER;
    BEGIN
       lv_length := length(pi_value);
       IF ( REGEXP_LIKE(pi_value,'[[:alnum:]]{'||lv_length||'}')) THEN
          RETURN 'TRUE';
       ELSE
          RETURN 'FALSE';
       END IF;
    END fn_is_alphanumeric;
    /(brackets should be doubled as compared with your original version).
    You can use both , range-based and class-based expressions, but you have to keep in mind, that range-based are nls dependant as opposite to class-based.
    SQL> alter session set nls_sort=binary;
    Session altered.
    SQL> with t as (
      2   select 'üäö123' s from dual
      3  )
      4  select
      5  case
      6  when regexp_like(s,'^[a-zA-Z0-9]+$') then 'Alphanumeric'
      7  else 'Not Alphanumeric'
      8  end range,
      9  case
    10  when regexp_like(s,'^[[:alnum:]]+$') then 'Alphanumeric'
    11  else 'Not Alphanumeric'
    12  end class
    13  from t
    14  /
    RANGE                CLASS
    Not Alphanumeric     Alphanumeric
    SQL>
    SQL> alter session set nls_sort='GERMAN';
    Session altered.
    SQL> with t as (
      2   select 'üäö123' s from dual
      3  )
      4  select
      5  case
      6  when regexp_like(s,'^[a-zA-Z0-9]+$') then 'Alphanumeric'
      7  else 'Not Alphanumeric'
      8  end range,
      9  case
    10  when regexp_like(s,'^[[:alnum:]]+$') then 'Alphanumeric'
    11  else 'Not Alphanumeric'
    12  end class
    13  from t
    14  /
    RANGE                CLASS
    Alphanumeric         AlphanumericBest regards
    Maxim

  • Random unguessable string

    We have the requirement from within our application to create a radom
    unguessable (or difficult to guess) string similar to that of the weblogic
    session key. I could simply create a session , grab the key and kill the
    session, but I this seems like a lot of overhead. Do you (weblogic) have any
    plans to expose your api for generating your keys, it would be nice since im
    sure you have probably gone through a lot to make sure its random and
    difficult to guess.
    thanks
    Joel

    yeah, but that would be a blatant violation of my license agreement with
    bea.. However if someone from bea said it was ok, that would work.
    -Joel
    <Alf> wrote in message news:3b6ac86a$[email protected]..
    You can decompile the classes for yourself (see
    weblogic.security.RandomBitsSource and others in the same package). As for
    the randomness, that needs to be tested. Depending on your requirements,
    relying on the assumption that WL produces sessionids with strongrandomness
    may not be enough.
    "Joel Nylund" <[email protected]> wrote in message
    news:[email protected]..
    We have the requirement from within our application to create a radom
    unguessable (or difficult to guess) string similar to that of the
    weblogic
    session key. I could simply create a session , grab the key and kill the
    session, but I this seems like a lot of overhead. Do you (weblogic) haveany
    plans to expose your api for generating your keys, it would be nice
    since
    im
    sure you have probably gone through a lot to make sure its random and
    difficult to guess.
    thanks
    Joel

  • Random pick string...

    how to random pick the string out....when we set the total for string eg:
    string a = " how to pick out the string"
    if i choose 3 string out,
    result: how to pick....or......pick out the....or out the string...

    Or if it is not consectutive words that you want you could build a one dimensional array, containing the numbers 1-->number of words in sentence, in the corresponding array positions. Then you could shuffle the array and read of the first n elements of the array. The number in each entry represents an index for the array of words and then you can simply get the entry at that index.
    eg. simple suffle method, randomly pick an item and move to the end of the array.
    static void shuffle(int[] A) {
            for (int lastPlace = A.length-1; lastPlace > 0; lastPlace--) {
                  // Choose a random location from among 0,1,...,lastPlace.
               int randLoc = (int)(Math.random()*(lastPlace+1));
                  // Swap items in locations randLoc and lastPlace.
               int temp = A[randLoc];
               A[randLoc] = A[lastPlace];
               A[lastPlace] = temp;
         }hope this helps

  • Random Alphanumeric

    hello all,
    I want to generate 16 digit alphanumeric codes 0-9,A-Z.
    But they have to be unique whenever i run my code... also I should be able tell whether a particular code does exist or not....like for ex.
    123T67S9JK87
    345K88P5GH23
    from them WHICH IS VALID..?

    For generating those codes I can think of a solution (might not be the most elegant though) You can prepare an array containing the values 0 ... 9 and A ... Z. Whenever you need to generate a random ID, you just have to generate 16 random numbers between 0 and 35 (10 digits and 26 characters) and take the corresponding entry from the array...
    For checking for existence, provide a little more background on how you're using those codes in your program, where they're parked after creation...

  • Sort Alphanumeric string in OBIEE answers

    Hi...
    I have a time slot column in my table. I holds data as follows,
    10AM-12PM
    9AM-11AM
    11AM-1PM
    How to sort the report with these column. If i sort it, it was showing data as follows.
    10AM-12PM
    11AM-1PM
    9AM-11AM
    Can u please help to reslove the issue

    If you are specifically trying to use a string function to resolve your issue, then you can try below.
    Pull another slot column in your Answers request and use evaluate function, to derive a timestamp (using oracle to_date funtion) column. Then you can sort this column and hide it in your report.
    Something like below can be used derive timestamp from say '10AM-11AM':
    select to_date(substr('10AM-11AM',1,instr('10AM-11AM','-')-1),'HHAM') from dual --Output 2011-09-01 10:00:00
    Similarly,
    select to_date(substr('10PM-11PM',1,instr('10PM-11PM','-')-1),'HHAM') from dual --Output 2011-09-01 22:00:00
    See if it suits your requirement.
    Thanks

  • Leading zeros to alphanumeric string

    Hello all ,
    Does anybody know any function module to put leading zeros to an alphanumeric sequence (18 characters)?
    Example : 12wer should be '000000000000012wer'
    CONVERSION_EXIT_ALPHA_INPUT only works with numbers.
    Thanks in advance ,
    Snehal

    Hi Snehal,
    <pre>
    shift [field] right deleting trailing ' '.
    replace ' ' in [field] with '0'.
    </pre>
    OK?
    Regards,
    Clemens

  • How to sort multiple combinations alphanumeric Strings

    Hi All,
    I have problem that
    i need to sort 1A1a,1Aa,1Aa1,1B1a........................
    as 1Aa,1A1a,1Aa1,1B1a.......................
    can anybody help me....
    Thanks
    Anil.

    I have problem that i need to sort
    1A1a,1Aa,1Aa1,1B1a........................
    as 1Aa,1A1a,1Aa1,1B1a.......................Build a Comparator that implements the ordering rule you want.
    (I can't figure out the order from the example you showed).
    kind regards,
    Jos

Maybe you are looking for

  • What is the best way to get/change data in R/3 from external interface?

    Hi SAP gurus, I have a problem to know what is the best technology to access and maintenance all SAP functionality and data too in R/3 systems. Anyone know if connectors (.NET or JCO) are the only solution to manipulate all SAP system data or exist o

  • How can I add text to a reply message on Mac

    When replying to an email message via the Mail.app (on Mac), I would like my lines to have my name at the beginning of the line, and have it in a different font (similar to what Outlook does). I was thinking of writing an AppleScript that will insert

  • At Photo Gallery is there a button to transport viewer back to my website?

    I don't yet have iLife '08 but my question is: RE: Photo Gallery I am assuming that in my iWeb website I must place URLs of each photo page that I make. Question: Once the person is there at the Photo Gallery, is there a button that can get him BACK

  • Weblogic 8.1 SP2 does not support 'Order by' clause in EJB-QL

    It seems that Weblogic 8.1 SP2 does not support 'Order by' clause in EJB-QL. EJB 2.1 spec supports 'Order by' clause in EJB-QL. Am I right when I say that it indicates : "Weblogic 8.1 SP2 does not support EJB 2.1" ? In that case, what can be the alte

  • Javah -jni throws error

    I' m trying to create appropriate *.h file by javah utility as discribed in java tutorial javah -jni MyClass but get the error message Class MyClass can not be found... the class MyClass is in the same directory from where i run "javah -jni MyClass"