Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:27:08+00:00 2026-05-28T21:27:08+00:00

Given any particular rectangle (x1,y1)-(x2,y2), how can I generate a random point on its

  • 0

Given any particular rectangle (x1,y1)-(x2,y2), how can I generate a random point on its perimeter?

I’ve come up with a few approaches, but it seems like there ought to be a pretty canonical way to do it.

First, I thought I’d generate a random point within the rectangle and clamp it to the closest side, but the distribution didn’t seem uniform (points almost never fell on the shorter sides). Second, I picked a side at random and then chose a random point on that side. The code was kind of clunky and it wasn’t uniform either – but in the exact opposite way (short sides had the same chance of getting points as long sides). Finally, I’ve been thinking about “unfolding” the rectangle into a single line and picking a random point on the line. I think that would generate a uniform distribution, but I thought I’d ask here before embarking down that road.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:27:09+00:00Added an answer on May 28, 2026 at 9:27 pm

    Your last approach is what I would have recommended just from reading your title. Go with that. Your second approach (pick a side at random) would work if you picked a side with probability proportional to the side length.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've heard that given a programmer with enough time and skill in any particular
For any given type i want to know its default value. In C#, there
Estimating how long any given task will take seems to be one of the
When writing PHP code for any given project, do you find you can write
Given any arbitrary, one-line string, my goal is to render it into a bitmap
given any number, what's the best way to determine it is even? how many
Given any iterable, for example: ABCDEF Treating it almost like a numeral system as
For any given NSManagedObject, is there any method to return a set or array
I'm trying to compress any given string to a shorter version, copy paste-able compressed
I'm capturing a click on any given LI in: <ul> <li class=opt>Text 1</li> <li

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.