Friday, November 2, 2012

Random String generator


import lrapi.lr;

public class Actions
{
      randomGen randgen;

      public int init() throws Throwable {
return 0;
}//end of init


public int action() throws Throwable {
randgen = new randomGen();
String randStringAct = randgen.randomGen(5);
System.out.println("returned in Action:" + randStringAct);
return 0;
}//end of action



public int end() throws Throwable {
return 0;
}//end of end

}
----------------
public class randomGen
{
    String randomString = "";

public String randomGen ( int length)
{
   for (int count = 0; count < length; count ++) {
    char randomChar = (char)((int)'A'+Math.random()*((int)'Z'-(int)'A'+1));
    randomString = randomChar + randomString;
   }
        System.out.println("RandomString in Funct: " + randomString);
return randomString;

}
}

No comments:

Post a Comment