import java.util.Random;  
public static void main(String[] args) {
    System.out.println(new Random().nextInt(90)+10); //86 (取10~99)
    System.out.println(new Random().nextInt(10));    //3  (取0~9)
    System.out.println(new Random().nextInt(9)+1);   //4  (取1~9)
    System.out.println(new Random().nextInt(2));     //1  (取0~9)
}

new Random().nextInt(n):取0~(n-1)之正整數

n需為正數

refer:  https://docs.oracle.com/javase/7/docs/api/java/util/Random.htm

    咪卡恰比 發表在 痞客邦 留言(0) 人氣()