这题大概的意思就是先生成一个正方形,然后再取点,如果取到了,就退出,没有就继续
import java.util.Random;
/**
* @author xnl
* @Description:
* @date: 2022/6/5 22:11
*/
public class Solution {
public static void main(String[] args) {
}
double x, y, radius;
Random random;
public Solution(double radius, double x_center, double y_center) {
random = new Random();
this.radius = radius;
this.x = x_center;
this.y = y_center;
}
public double[] randPoint() {
while (true){
double xc = random.nextDouble() * (radius * 2) - radius;
double yc = random.nextDouble() * (radius * 2) - radius;
if (xc * xc + yc * yc <= radius * radius){
return new double[]{xc + x , yc+ y};
}
}
}
}