1 Reply Latest reply: Sep 24, 2006 11:27 PM by 807598 RSS

    Random String Generation

    807598
      Hi I have a problem where I want to generate a Random String from a list of Strings. EG. from { east, west, north, south} now every time generate one out of this 4 strings. is it possible?
        • 1. Re: Random String Generation
          807598
          there are many ways to do it ,one way is

          store the strings in an array and retrive them randomly try this
          private String randomString(){          
                    String depts[] ={"East","West","North","South"}; 
                    Random randomNumber = new Random();
                    int deptNo = randomNumber.nextInt(4);          
                    return depts[deptNo];
               }
          null