Hi,

As per my understanding you are trying to generate a random number within a box/plane.

Note, that the following method will work only for axis aligned boxes.

The key ideas involved are:

- Generate random x and y coordinates independently within the limits of the box (x_min, x_max) and (y_min and y_max).
- For generating a random number in the range [a,b], draw a random number in interval [0,1]. Map the interval [0,1] to the interval [a,b].

You can make use of the rand(n) function to generate a random number within [0,1]. Following example illustrates the process:

The generated value of r always lies within [50,100].

You can generate a random x-coordinate within the range of [p,x] and a random y-coordinate within the range of [q,y]. The randomly generated point will always lie within the box. For 3D space you can similarly generate the z-coordinate.

For non-aligned other boxes:

- Perform inverse rotations such that the box is axis aligned. Suppose box is rotated by theta, rotate points of box by –theta.
- Find the random point in the inverse rotated box.
- Rotate the random point by theta to map it to rotated(original) box.

For more details on random number generation within a specific range, refer to the following documentation:

https://in.mathworks.com/help/matlab/math/floating-point-numbers-within-specific-range.html