Generate Random Point in a Circle LeetCode solution in JavaScript

1
var Solution = function (radius, x_center, y_center) {
2
this.radius = radius;
3
this.x_center = x_center;
4
this.y_center = y_center;
5
};
6

7
Solution.prototype.randPoint = function () {
8
let r = this.radius * Math.sqrt(Math.random());
9
let theta = Math.random() * 2 * Math.PI;
10
let x = this.x_center + r * Math.cos(theta);
11
let y = this.y_center + r * Math.sin(theta);
12
return [x, y];
13
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0