package com.UUU.util;
public class KaoShi {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
System.out.print(random9() + " ");
}
}
/**
* 根据random8,生成[1,9]之间的随机数
*
* @return
*/
private static int random9() {
int x;
do {
x = random8() * 8 + random8();
} while (x == 8 * 8 - 1);
return x % 9 + 1;
}
/**
* 生成[1,8]之间的随机数
*
* @return
*/
private static int random8() {
int r = (int) (Math.random() * 8) + 1;
return r;
}
}
public class KaoShi {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
System.out.print(random9() + " ");
}
}
/**
* 根据random8,生成[1,9]之间的随机数
*
* @return
*/
private static int random9() {
int x;
do {
x = random8() * 8 + random8();
} while (x == 8 * 8 - 1);
return x % 9 + 1;
}
/**
* 生成[1,8]之间的随机数
*
* @return
*/
private static int random8() {
int r = (int) (Math.random() * 8) + 1;
return r;
}
}