What's wrong with my solution of using random numbers
I am saving all the rectagles and then picking one rectangle from among them and then I am picking a x that is between the min and max x of that rectangle and t
I am saving all the rectagles and then picking one rectangle from among them and then I am picking a x that is between the min and max x of that rectangle and then picking a y that is between the min and max of that rectangle. Could anyone point out to me what I am doing wrong here?\n\n```\nclass Solution {\n    int recta[][];\n    Random r = new Random();\n    public Solution(int[][] rects) {\n        this.recta = new int[rects.length][5];\n        for(int i = 0; i < rects.length; i++){\n            this.recta[i][0] = rects[i][0];\n            this.recta[i][1] = rects[i][1];\n            this.recta[i][2] = rects[i][2];\n            this.recta[i][3] = rects[i][3];\n            int dist = (int)Math.pow(Math.abs(rects[i][0] - rects[i][2]), 2) + (int)Math.pow(Math.abs(rects[i][1] - rects[i][3]), 2);\n            this.recta[i][4] = dist;\n        }\n    }\n    \n    public int[] pick() {\n        int tot = 0;\n        for(int[] r : this.recta){\n            tot += r[4];\n        }\n        // Now choose a random item\n        int recNum = -1;\n        double random = Math.random() * tot;\n        for (int i = 0; i < this.recta.length; ++i)\n        {\n            random -= this.recta[i][4];\n            if (random <= 0.0d)\n            {\n                recNum = i;\n                break;\n            }\n        }\n        \n        int xMax = this.recta[recNum][0] > this.recta[recNum][2] ? this.recta[recNum][0] : this.recta[recNum][2] ;\n        int xMin = this.recta[recNum][0] < this.recta[recNum][2] ? this.recta[recNum][0] : this.recta[recNum][2] ;\n        int yMax = this.recta[recNum][1] > this.recta[recNum][1] ? this.recta[recNum][1] : this.recta[recNum][3] ;\n        int yMin = this.recta[recNum][1] < this.recta[recNum][3] ? this.recta[recNum][1] : this.recta[recNum][3] ;\n        \n        \n        \n        int xR = Integer.MIN_VALUE;\n        int yR = Integer.MIN_VALUE;\n        if(xMax == xMin)\n            xR = xMax;\n        else\n         xR = xMin + r.nextInt(xMax-xMin);\n        if(yMax == yMin)\n            yR = yMax;\n        else\n          yR = yMin + r.nextInt(yMax-yMin);\n        int[] coor = new int[2];\n        coor[0] = xR;\n        coor[1] = yR;\n        return coor;\n    }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(rects);\n * int[] param_1 = obj.pick();\n */\n```
[]