Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
18   82   10   3
8   45   0.56   6
6     1.67  
1    
 
 
  RandomGenerator       Line # 11 18 10 93.8% 0.9375
 
  (1)
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: mike
4    * Date: Jan 23, 2002
5    * Time: 6:10:02 PM
6    * To change template for new class use
7    * Code Style | Class Templates options (Tools | IDE Options).
8    */
9    package com.atlassian.core.util;
10   
 
11    public class RandomGenerator
12    {
13    /**
14    * Generate a random password (length 6)
15    */
 
16  2 toggle public static String randomPassword()
17    {
18  2 return randomString(6);
19    }
20   
21    /**
22    * Generate a random string of characters - including numbers
23    */
 
24  2 toggle public static String randomString(int length)
25    {
26  2 return randomString(length, true);
27    }
28   
29    /**
30    * Generate a random string of characters
31    */
 
32  2 toggle public static String randomString(int length, boolean includeNumbers)
33    {
34  2 StringBuffer b = new StringBuffer(length);
35   
36  14 for (int i = 0; i < length; i++)
37    {
38  12 if (includeNumbers)
39  12 b.append(randomCharacter());
40    else
41  0 b.append(randomAlpha());
42    }
43   
44  2 return b.toString();
45    }
46   
47    /**
48    * Generate a random alphanumeric character.
49    *
50    * 3/4rs of the time this will generate a letter, 1/4 a number
51    */
 
52  12 toggle public static char randomCharacter()
53    {
54  12 int i = (int) (Math.random() * 3);
55  12 if (i < 2)
56  9 return randomAlpha();
57    else
58  3 return randomDigit();
59    }
60   
61    /**
62    * Generate a random character from the alphabet - either a-z or A-Z
63    */
 
64  9 toggle public static char randomAlpha()
65    {
66  9 int i = (int) (Math.random() * 52);
67   
68  9 if (i > 25)
69  4 return (char) (97 + i - 26);
70    else
71  5 return (char) (65 + i);
72    }
73   
74    /**
75    * Generate a random digit - from 0 - 9
76    */
 
77  3 toggle public static char randomDigit()
78    {
79  3 int i = (int) (Math.random() * 10);
80  3 return (char) (48 + i);
81    }
82    }