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

Similar Messages

  • 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;
    }

  • 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

  • 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)

  • 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

  • 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

  • Randomly Generate alpha-numeric strings?

    Hi, can somebody help me to randomly generate strings such as A1, B5, E 2, etc. The range for the values I need generated are [A-E][1-5]. I looked at lots of code for Random generating numbers, but found nothing related to what I need. I hope somebody can help me out here. Thanks!

    nevermind, i figured it out! thanks anyway

  • Unique random alpha num string

    Hi Guys,
    I have a unique question.
    I need to generate a unique random Alpha Num string.
    I cannot use 0,5,8 and 0,S,B in the generated output string.
    The string generated should be no more than length 7 max
    Pls help.

    Following solution generates random unique strings combinations
    from any given base set. Here is a sample output.
    $ java UniqueStringGenerator 7 100 10
    FCT2RYT
    2M31BU8
    VV8FU4Z
    BON2MKE
    OKUJZT0
    68E8X8S
    YTNLZAY
    CPEKPFP
    C176M24
    GQB9QE9The idea is quite simple.
    Pre-work:
    1. The base set is first mixed to increase entropy.
    2. All possible combinations are divide up into random buckets.
    Work for every unique string:
    1. Pick a bucket at random.
    2. Get next number in bucket.
    3. Convert the number to a unique string token.
    It is possible to adjust how much entropy you want in your
    sequence of generated combinations by choosing how many buckets
    the generator contains. However, every bucket will take up some
    memory.
    import java.util.*;
    import java.math.*;
    public class UniqueStringGenerator {
        public static String[] ALPHA_NUM =
         {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
          "Q","R","S","T","U","V","X","Y","Z",
          "0","1","2","3","4","5","6","7","8","9"};
        private List _parts = null;
        private List _buckets = null;
        private int _length;
        private BigInteger _range = null;
        public UniqueStringGenerator(String[] parts, int length,
                         int numberOfBuckets) {
         _length = length;
         // mixing the base set to increase entropy
         _parts = new Vector();
         List all = new Vector();
         for (int i = 0;i < parts.length;i++) {
             all.add(parts);
         while (all.size()>0) {
         int p = (int)(((double)all.size())*Math.random());
         _parts.add(all.get(p));
         all.remove(p);
         // dividing all possible numbers into given number of buckets
         BigInteger numParts = BigInteger.valueOf(parts.length);
         _range = BigInteger.ONE;
         for (int i = 0;i<_length;i++) {
         range = range.multiply(numParts);
         TreeSet starts = new TreeSet();
         Random rand = new Random();
         while (starts.size()<numberOfBuckets-1) {
         BigInteger bi = new BigInteger(_range.bitLength(), rand);
         if (bi.compareTo(_range)<=0) {
              starts.add(bi);
         _buckets = new Vector();
         Bucket last = new Bucket(BigInteger.ZERO);
         _buckets.add(last);
         for (Iterator i = starts.iterator();i.hasNext();) {
         Bucket next = new Bucket((BigInteger)i.next());
         _buckets.add(next);
         last.setTo(next.getStart());
         last = next;
         last.setTo(_range);
    private class Bucket {
         private BigInteger _start;
         private BigInteger _next;
         private BigInteger _to;
         public Bucket(BigInteger start) {
         _start = start;
         _next = start;
         public void setTo(BigInteger to) {
         _to = to;
         public BigInteger getStart() {
         return _start;
         public boolean hasNext() {
         return next.compareTo(to)<0;
         public BigInteger next() {
         BigInteger ret = _next;
         next = next.add(BigInteger.ONE);
         return ret;
         public String toString() {
         return "["+start+", "+next+", "+_to+"]:"+hasNext();
    public String nextUnique() {
         // getting next big integer
         BigInteger left = null;
         while (left==null) {
         Bucket b = (Bucket)
              buckets.get((int)(Math.random()*buckets.size()));
         if (b.hasNext()) {
              left = b.next();
         // converting it to a combination
         StringBuffer unique = new StringBuffer();
         BigInteger base = BigInteger.valueOf(_parts.size());
         for (int i = 0;i<_length;i++) {
         BigInteger[] resRem = left.divideAndRemainder(base);
         left = resRem[0];
         unique.append(_parts.get(resRem[1].intValue()));
         return unique.toString();
    public static void main(String[] args) {
         if (args.length!=3) {
         System.out.println("Usage: UniqueStringGenerator "+
                   "[string size] [# buckets] [# prints]");
         return;
         int length = Integer.parseInt(args[0]);
         int numBuckets = Integer.parseInt(args[1]);
         int num = Integer.parseInt(args[2]);
         UniqueStringGenerator usg = new UniqueStringGenerator
         (UniqueStringGenerator.ALPHA_NUM, length, numBuckets);
         for (int i=0;i<num;i++) {
         System.out.println(usg.nextUnique());

  • Cp4 AS3 - using Javascript to generate a text string

    I'm a complete Javascript beginner, so please forgive me if this is a stupid question!
    I need to generate a pseudo random text string. I'm using the unpatched version of Cp4, AS3, Internet Explorer 7
    I've had a look at Captivate.Dev.com and the w3schools site to try to understand how to pass variables & basic javascript, and this is what I've come up with:
    var objCP = document.Captivate;
    function GenerateCode(){
    var rngen = new Array(8);
    var tgits = new Array(8);
    var cdrtn="";
    var lpdx=0;
    var mulier=1;
    for (lpdx=0;lpdx<=5;lpdx++){
    rngen[lpdx]=(Math.floor(Math.random()*9)+1);
    mlier=mulier*(rngen[lpdx]);
    tgits[lpdx]=rngen[lpdx]+"";
    cdrtn=cdrtn+tgits[lpdx];
    rngen[6]=(mlier%17)%10;
    rngen[7]=(mlier%13)%10;
    for (lpdx=6;lpdx<=7;lpdx++)
    tgits[lpdx]=rngen[lpdx]+"";
    cdrtn=cdrtn+tgits[lpdx];
    objCP.cpEISetValue('MyJavascriptVariable', cdrtn);
    GenerateCode();
    I've created a user variable called MyJavascriptVariable , put the code above in the On Slide Enter, Execute Javascript window on the first slide, and on the second a simple caption box showing the variable contents.
    However, when I press F12 I get an orange playbar at the top of the window, and in the middle the preloader and the captionbox (without the return value) flickering. i.e. classic sign of wrong AS version.
    If I change to AS2 the movie progresses ok, but the value the caption reports back for MyJavascriptVariable is blank.
    I know my core code works correctly - if I use the w3school's tryit editor with the code after the function declaration up to the closing curly before the objcCP line, with an addeded document.write to show the variable it works fine.
    It's clearly something to do with the way I'm declaring/passing the function or the way Cp runs the javascript. But what?
    Any help greatfully appreciated!
    Thanks

    Hi Jon,
    You are right... it works great on the W3Schools site.  Although in Cp, you ran into quite an issue using the modulus operater (%).  Looks like Cp needs the encoded version of this operator which is (%25).  Also, if you're using Cp4, then when you go to set the caption, you want to use objCP.cpSetValue();  Cp5 uses cpEISetValue.  I also try to use single quotes when working with strings.
    Here's the updated code:
    var objCP = document.Captivate;
    function GenerateCode() {
    var rngen = new Array(8);
    var tgits = new Array(8);
    var cdrtn='';
    var lpdx = 0;
    var mulier=1;
        for (lpdx=0; lpdx<=5; lpdx++){
            rngen[lpdx]=(Math.floor(Math.random()*9)+1);
            mlier=mulier*(rngen[lpdx]);
            tgits[lpdx]=rngen[lpdx]+'';
            cdrtn=cdrtn+tgits[lpdx];
    rngen[6]=(mlier %25 17) %25 10;
    rngen[7]=(mlier %25 13) %25 10;
       for (lpdx=6; lpdx<=7; lpdx++){
            tgits[lpdx]=rngen[lpdx]+'';
            cdrtn=cdrtn+tgits[lpdx];
    objCP.cpSetValue('MyJavascriptVariable', cdrtn);
    GenerateCode();
    This looks like some really crazy math.
    Let me know if this helps.
    Jim Leichliter

  • Query on conversion between String to Enum type

    Hi All,
    I would like to get advice on how to convert between char and Enum type. Below is an example of generating unique random alphabet letters before converting them back to their corresponding letters that belonged to enum type called definition.Alphabet, which is part of a global project used by other applications:
    package definition;
    public enum Alphabet
    A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S,
    T, U, V, W, X, Y, Z
    public StringBuffer uniqueRandomAlphabet()
    String currentAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuffer randomAlphabetSB = new StringBuffer();
    for (int numberOfAlphabet=26; numberOfAlphabet>0; numberOfAlphabet--)
    int character=(int)(Math.random()* numberOfAlphabet);
    String characterPicked = currentAlphabet.substring(character, character+1);
    // System.out.println(characterPicked);
    randomAlphabetSB.append(characterPicked);
    StringBuffer remainingAlphabet = new StringBuffer( currentAlphabet.length() );
    remainingAlphabet.setLength( currentAlphabet.length() );
    int current = 0;
    for (int currentAlphabetIndex = 0; currentAlphabetIndex < currentAlphabet.length(); currentAlphabetIndex++)
    char cur = currentAlphabet.charAt(currentAlphabetIndex);
    if (cur != characterPicked.charAt(0))
    remainingAlphabet.setCharAt( current++, cur );
    currentAlphabet = remainingAlphabet.toString();
    return randomAlphabetSB;
    // System.out.println(randomAlphabetSB);
    I got the following compilation error when trying to pass (Alphabet) StringBuffer[0] to a method that expects Alphabet.A type:
    inconvertible types
    required: definition.Alphabet
    found: char
    Any ideas on how to get around this. An alternative solution is to have a huge switch statement to assemble Alphabet type into an ArrayList<Alphabet>() but wondering whether there is a more shorter direct conversion path.
    I am using JDK1.6.0_17, Netbeans 6.7 on Windows XP.
    Thanks a lot,
    Jack

    I would like to get advice on how to convert between char and Enum type. Below is an example of generating unique random alphabet lettersIf I understand well, you may be interested in method shuffle(...) in class java.util.Collections, which randomly reorders a list.
    before converting them back to their corresponding letters that belonged to enum type called definition.AlphabetIf I understand well, you may be interested in the built-in method Alphabet.valueOf(...) which will return the appropriate instance by name (you'll probably have no problem to build a valid String name from a lowercase char).

  • Random text with links using Javascript?

    I have a very simple script I downloaded that makes text random using javascript. I would like to add a hypertext link on parts of the text, but can't seem to get it to work.
    Would anyone be so kind as to show me how this can be done. I would like to add links to the "Random text string 1.", Random text string 2. etc., within the javascript below.
    <SCRIPT LANGUAGE="Javascript"><!--
    function text() {
    text = new text();
    number = 0;
    // textArray
    text[number++] = "Random text string 1."
    text[number++] = "Random text string 2."
    text[number++] = "Random text string 3."
    text[number++] = "Random text string 4."
    text[number++] = "Random text string 5."
    // keep adding items here...
    increment = Math.floor(Math.random() * number);
    document.write(text[increment]);
    //--></SCRIPT>
    Thank you!

    Hi, Mic,
    I actually don't know if this will work, but what if you added <a href> coding around your text line? You might need \ escape characters so that your script sends it out without trying to execute it as code.
    Z

  • I'm trying to create a random color generator

    //               create random color generator
                        String[]colors = {"RED", "ORANGE", "YELLOW", "GREEN", "BLUE", "INDIGO", "PURPLE"};
    //               create variable to store random color
                        int mycolorint = (int)(Math.random()*7);
                        String mycolor = colors[mycolorint];
    //               label axis
                   StdDraw.setPenColor(StdDraw.(mycolor));
    what is wrong with this code?

    StdDraw.setPenColor(StdDraw.(mycolor));This line really doesn't make any sense. If you think about it you haven't seen any java code which includes something like "foo.(bar)" or "Foo.(bar)". The compiler wants to see identifiers either side of the dot - and identifiers don't start with a (.
    I am guessing that if "RED" gets chosen from the array, then you want the label axis to useStdDraw.setPenColor(StdDraw.RED);In that case you have to set the array up a little differently.
        // create random color generator
    ???[]colors = {
            StdDraw.RED, StdDraw.ORANGE, StdDraw.YELLOW,
            StdDraw.GREEN, StdDraw.BLUE, StdDraw.INDIGO, StdDraw.PURPLE
        // create variable to store random color
    int mycolorint = (int)(Math.random() * 7);
    ??? mycolor = colors[mycolorint];
        // label axis
    StdDraw.setPenColor(mycolor);You will have to read the documentation for this StdDraw class to see what type StdDraw.RED etc are.

  • How to convert char array to string

    sirs,
    i have written a method in java which will return a randomly generated string of a fixed length. i am creating one one character and inserting it into char array.
    at last i am converting it to string
    like this
    String newpass= pass.toString();// pass is a char array
    but problem is that the string is having different value what i hav generated.
    if i am doing like this..
    String newpass= new String(pass);// pass is a char array
    here newpass is having correct value but having some error
    error in the sense when i print
    System.out.println(newpass+"some text");
    "some text" is not printing
    can you suggest the better way

    /*this is my method */
    private String generateString(int len){
              char pass[] = new char[10];
              int cnt=0;
              int temp=0;
              Random randomGenerator = new Random();
                   for (int idx = 0; idx < 1000; ++idx)
                        temp = randomGenerator.nextInt(1000)%128;
                   if((temp>=65 && temp<=90)||(temp>=97 && temp<=122)||(temp>=48 && temp<=57))
                             pass[cnt]=(char)temp;
                             cnt++;               
                        if(cnt>=len) break;
                   String newpass= pass.toString();
                   String newpass1= new String(pass);
                   System.out.println("passed pass"+newpass+"as"+newpass1+"sa");
              return newpass;
    here newpass and newpass1 are having separate values
    why ??
    Edited by: Shovan on Jun 4, 2008 2:21 AM

  • Random+Timer

    I want to make the applet that will:
    have 3 Labels,
    1 textbox,
    2 button.
    When u press button # 1 it generates 2 random numbers and shows those in labels. What am i doing wrong?:
    * Random.java
    * author George K and
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.Random;
    import java.io.*;
    public class Random2 extends Applet implements ActionListener
    Label onLabel = new Label(" ");// Nice GUI to help user know.
    Label twLabel = new Label(" ");
         TextField bb2TextField = new TextField(35);
         Label errLabel = new Label("");
    Button okButton = new Button("PRESS ME"); //BUTTON!!!!
                        public void init()
                        add(onLabel);
                        add(bb2TextField);
                        add(twLabel);
                        add(okButton);
                        okButton.addActionListener(this);
                        add(errLabel);
                        Random r = new Random(10);
                        Random r2 = new Random(10);
                        String v1 = String.valueOf(r);
                        String v3 = String.valueOf(r2);
                   public void actionPerformed(ActionEvent evt)
         Random r = new Random(10);
                        Random r2 = new Random(10);
                        String v1 = String.valueOf(r);
                        String v2 = String.valueOf(r2);
              onLabel.setText(v1);
              twLabel.setText(v2);
              int rr2=Integer.parseInt(bb2TextField.getText());
              // setBackground(new java.awt.Color(Color.Red));
    }

    I changed it and it compiles like its suppos to, but there is some kind of logical error, whn i start it, it always gives me the same numbers: 1 and 3. Any help?
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.Random;
    import java.io.*;
    public class Random2 extends Applet implements ActionListener
         Label onLabel = new Label("");
         Label twLabel = new Label("");
         TextField bb2TextField = new TextField(35);
         Label errLabel = new Label("");
        Button okButton = new Button("PRESS ME"); //BUTTON!!!!
                        public void init()
                        add(onLabel);
                        add(bb2TextField);
                        add(twLabel);
                        add(okButton);
                        okButton.addActionListener(this);
                        add(errLabel);
                   public void actionPerformed(ActionEvent evt) 
                        Random r = new Random(10);
                        int v1 = r.nextInt(10);
                        int v2 = r.nextInt(10);
                   String v4 = String.valueOf(v1);
                   String v3 = String.valueOf(v2);
                      onLabel.setText(v3);
                       twLabel.setText(v4);
            }}

  • Random number game

    I am writing a random numbre game which produces 6 random numbers which all must be different and within a certain range. Currently all I can get output is 6 numbers where I have duplicates e.g.
    6
    6
    6
    36
    45
    32
    How do I make the 6 numbers different ?
    Here's a small sample of the code to give you the basic idea:
    import java.util.*;
    public class Random
    private String rNumber;
         public Random()
         String[] numlist = new String[2];
    numlist[0] = "1";
    numlist[1] = "2";
    Random rand = new Random();
         int x = (int) (0 + (Math.abs(rand.nextInt()) % 1 )) ;
         rNumber = number[x];
         public String getrNumber()
         return rNumber;
    public static void main(String args[])
         for (int i=0; i<6; i++){
         String rn;
         Random num = new Random();
    rn = num.getrNumber();
    System.out.println(rn);
    }

    Use a simple if statement that calls a method that will return a boolean value based on the random number generated(and now in english).
    (1)Generate your number.
    (2)Use the number as a parameter to a method.(This method checks to see if the number is already in the data structure(array,stack, whatever).
    /** Checks if the given number is already contained in the given array **/
    public boolean isDuplicate(int num,int[] array) {
    // I have passed an array just to make it clearer.
    for(int i=0;i<array.length;i++) {
    if(array[i] == num) return true;
    return false; // if the number is not a duplicate we know it is okay to put in our array.
    // remember to keep some kind of reference to the array position.
    (3) Now we just put this in the next number position in our array.
    Hope this helps, by the way you wouldn't be trying to generate some numbers for a Lottery would you?(I remember when I tried that and guess what-yeah still broke)
    Also call it something like RNGenerator not Random as this is already a Java class and it becomes a nightmare.

Maybe you are looking for