package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/generate-random-point-in-a-circle/
 */
public class Problem478 {
    private static class Solution {
        public Solution(double radius, double x_center, double y_center) {
            // TODO
        }

        public double[] randPoint() {
            // TODO
            return null;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution(1, 0, 0);
        System.out.println(Arrays.toString(solution.randPoint())); // [-0.72939,-0.65505]
        System.out.println(Arrays.toString(solution.randPoint())); // [-0.78502,-0.28626]
        System.out.println(Arrays.toString(solution.randPoint())); // [-0.83119,-0.19803]

        solution = new Solution(10, 5, -7.5);
        System.out.println(Arrays.toString(solution.randPoint())); // [11.52438,-8.33273]
        System.out.println(Arrays.toString(solution.randPoint())); // [2.46992,-16.21705]
        System.out.println(Arrays.toString(solution.randPoint())); // [11.13430,-12.42337]
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -163,186 +163,270 @@
    p
-ublic Solution(double radius, double x_center, double y_center) %7B%0A            // TODO%0A        %7D%0A%0A        public double%5B%5D randPoint() %7B%0A            // TODO%0A            return null
+rivate final double radius;%0A        private final double x;%0A        private final double y;%0A%0A        public Solution(double radius, double x_center, double y_center) %7B%0A            this.radius = radius;%0A            this.x = x_center;%0A            this.y = y_center
 ;%0A  
@@ -437,15 +437,13 @@
   %7D%0A
+%0A
     
-%7D%0A%0A
     
@@ -453,680 +453,367 @@
 lic 
-static void main(String%5B%5D args) %7B%0A        Solution solution = new Solution(1, 0, 0);%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B-0.72939,-0.65505%5D%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B-0.78502,-0.28626%5D%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B-0.83119,-0.19803%5D%0A%0A        solution = new Solution(10, 5, -7.5);%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B11.52438,-8.33273%5D%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B2.46992,-16.21705%5D%0A        System.out.println(Arrays.toString(solution.randPoint())); // %5B11.13430,-12.42337%5D
+double%5B%5D randPoint() %7B%0A            // https://en.wikipedia.org/wiki/Polar_coordinate_system%0A            double area = Math.random() * Math.PI * radius * radius;%0A            double r = Math.sqrt(area / Math.PI);%0A            double theta = Math.random() * 2 * Math.PI;%0A            return new double%5B%5D%7BMath.cos(theta) * r + x, Math.sin(theta) * r + y%7D;%0A        %7D
 %0A   

Solve problem 478