代码
方法一:
public class RandomTest extends TestCase {   
    
public void testRandom1() throws Exception {   
        String s 
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";   
        
char[] c = s.toCharArray();   
        Random random 
= new Random();   
        
forint i = 0; i < 8; i ++) {   
            System.out.println(c[random.nextInt(c.length)]);   
        }   
    }   
}  


方法二:
public void testRandom2() throws Exception {   
    Random random 
= new Random();   
    
forint i = 0; i < 8; i ++) {   
        
int choice = random.nextInt(2% 2 == 0 ? 65 : 97// 取得大写还是小写   
        System.out.println((char)(choice + random.nextInt(26)));   
    }   

 

 

posted on 2009-12-05 15:27  jdonson  阅读(2882)  评论(0编辑  收藏  举报