What is some good TI-BASIC code for randomly generating a point on the boundary of a square? Assume the square's vertices are at (0,0), (0,1), (1,0), and (1,1) (I'll try and generalize myself), and the point to be generated is stored on (A,B).

I assume I'd have to use rand and some conditional, but I can't begin to guess a nice compact way to do it.

To be clear, I don't mean inside. I mean exactly on the boundary. To avoid confusion.

Found a version.

EDIT:

never mind it's stupid

If the output being in a list variable is okay/desired, I've got this:

**Code:** ```
rand(2→L₁
```

int(2rand→L₁(randInt(1,2

Thanks Runer! I'm having trouble seeing how to generalize it, though. I have a formula for where (A,B) and (C,D) are opposite points on a rectangle, generating a random ordered pair on the rectangle:

**Code:** ```
int(2rand
```

{A+(C-A)(randAns+not(Ans)int(2rand)),B+(D-B)(randnot(Ans)+Ansint(2rand

Any way to improve this? I realize for my special case of a square, it can be simplified a bit.
Assuming a coordinate system (rectangle) from A to X and from B to Y, this code picks a random point on it:

**Code:** `(X-A)rand+A->PointX:(Y-B)rand+B-Y->PointY`

Generate a point inside the square and scale it so it lies on the boundary:

**Code:** ```
.5-rand(2
```

.5+.5Ans/max(abs(Ans

I don't know how to elegantly generate points on the rectangle given by (A,B) and (C,D).