Implemented method MText.getRandomToken().
authorMarco Zanon <info@marcozanon.com>
Mon, 26 Nov 2012 11:58:39 +0000 (11:58 +0000)
committerMarco Zanon <info@marcozanon.com>
Mon, 26 Nov 2012 11:58:39 +0000 (11:58 +0000)
3.x/src/java/com/marcozanon/macaco/text/MText.java

index e22f343725886a3404cd864c426985f1f1c3e322..5d90ca37dd5688ada3280c3b5ba14cff841e94cb 100644 (file)
@@ -56,6 +56,19 @@ public class MText extends MObject {
         return y.toString();
     }
 
+    public static String getRandomToken(int length) {
+        if (0 > length) {
+            throw new IllegalArgumentException(String.format("Invalid 'length': %s.", length));
+        }
+        //
+        StringBuilder y = new StringBuilder("");
+        for (int i = 0; i < length; i++) {
+            char c = (char)(65 + (25 * Math.random()));
+            y = y.append(c);
+        }
+        return y.toString();
+    }
+
     /* Javascript escape */
 
     public static String getJavascriptEscapedString(String x) {