Practice/Meta/Leetcode 478. Generate Random Point in a Circle
CodingMust
Design a class that generates uniformly distributed random points within a rectangular region. You need to implement a constructor that accepts the rectangle's dimensions and position, and a method that returns random points.
The constructor takes four parameters:
width: the width of the rectangle (positive float)height: the height of the rectangle (positive float)x_min: the x-coordinate of the bottom-left cornery_min: the y-coordinate of the bottom-left cornerImplement the randPoint() method that returns a random point [x, y] uniformly distributed within the rectangle (including the boundary).
RectangleSampler class must store the rectangle's dimensions and positionrandPoint() method must return a list/array of two floats representing [x, y] coordinatesrandPoint() should be independent and return a new random point0 < width ≤ 10^80 < height ≤ 10^8-10^7 ≤ x_min, y_min ≤ 10^73 * 10^4 calls will be made to randPoint()Example 1:
` Input: RectangleSampler(5.0, 3.0, 0.0, 0.0) randPoint() randPoint() randPoint()
Output: [2.4153, 1.8945] [4.7832, 0.2341] [1.0923, 2.9987]
Explanation: A rectangle with width 5, height 3, positioned at origin (0,0). All returned points have x in range [0, 5] and y in range [0, 3]. `
Example 2:
` Input: RectangleSampler(10.0, 10.0, -5.0, -5.0) randPoint() randPoint()
Output: [-2.3451, 3.8762] [4.1234, -1.9876]
Explanation: A square centered around the origin. Points have x and y coordinates in range [-5, 5]. `
Example 3:
` Input: RectangleSampler(1.0, 100.0, 0.0, 0.0) randPoint()
Output: [0.8234, 67.4523]
Explanation: A tall narrow rectangle. The x-coordinate is in [0, 1] and y-coordinate is in [0, 100]. `