KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > data > RandomString


1 package org.jboss.cache.data;
2
3 import java.util.*;
4
5 public class RandomString {
6
7        private static Random rn = new Random(12);
8
9        public static int rand(int lo, int hi)
10        {
11                int n = hi - lo + 1;
12                int i = rn.nextInt() % n;
13                if (i < 0)
14                        i = -i;
15                return lo + i;
16        }
17
18        public static String JavaDoc randomstring(int lo, int hi)
19        {
20                int n = rand(lo, hi);
21                byte b[] = new byte[n];
22                for (int i = 0; i < n; i++)
23                        b[i] = (byte)rand('a', 'z');
24                return new String JavaDoc(b, 0);
25        }
26
27        public static String JavaDoc randomstring()
28        {
29                return randomstring(5, 25);
30        }
31 }
32
33
Popular Tags