title: How to get random point near edges of a square in javascript
body: <p>I want to make a function that gives me a random point near the edges of a rectangle from a point. This is what I came up with so far, but I have absolutely no idea why it is not working.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function Point(x, y) {
    this.x = x;
    this.y = y;
  }
  
  function randomNumber(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  
  function getRandomPointNearEdges(rectPos, width, height, border) {
    var point = new Point(rectPos.x, rectPos.y);
    if (randomNumber(0, 1) == 0) {
      point.x = randomNumber(rectPos.x, rectPos.x + border);
      if (randomNumber(0, 1) == 0) {
        point.y = randomNumber(rectPos.y, rectPos.y + border);
      }
      else {
        point.y = randomNumber(rectPos.y + height, (rectPos.y + height) + border);
      }
    }
    else {
      point.y = randomNumber(rectPos.y, rectPos.y + border);
      if (randomNumber(0, 1) == 0) {
        point.y = randomNumber(rectPos.x, rectPos.x + border);
      }
      else {
        point.y = randomNumber(rectPos.x + height, (rectPos.x + width) + border);
      }
    }
    return point;
  };
  
  window.onload = function() {
    canvas = document.getElementById("canvas");
    canvas.width = 700;
    canvas.height = 700;
    var ctx = canvas.getContext("2d");
    ctx.strokeRect(130, 130, 500, 500);
    
    for (var i = 0; i &lt; 30; i++) {
      var point = getRandomPointNearEdges(new Point(130, 130), 500, 500, 100);
      ctx.fillRect(point.x, point.y, 2, 2);
    }
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;canvas id="canvas"&gt;&lt;/canvas&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>Just to clarify, the black region in this 'Not to scale' diagram is where I want to allow the point to generate. The width / height of that black region is the border property in the code snippet.</p>
  <p><a href="https://i.stack.imgur.com/7CcMp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7CcMp.png" alt="Diagram" /></a></p>
  <p>Why is my function not working?</p>