# Thread: Move points to the boundaries

1. ## Move points to the boundaries

I have some code, which gives me uniformly distributed points in d dimensions, inside a cube from min to max.

Let's take D = 2, min = - 1 and max = 1. The cube is actually a unit square. Let's generate 5 points.
Code:
```Generating 5 random points in a cube in 2D, coordinates from -1 to 1
-0.109367 0.749923
0.151204 0.859457
0.364111 0.94229
-0.740006 -0.497918
-0.111803 0.289617```
What I would like to do, is to get, uniformly distributed, the points that lie in the boundaries of the D - cube.
I thought about generating the points with the code I have unitl now and simply replacing a coordinate with min or max. This will produce boundary points, but are they uniformly distributed? Take as granted, that the points that are generated already are uniformly distributed!

2. If the RNG you are using is capable of generating uniformly distributed numbers between 0 and 1 (which most can, including language standard libraries), you can generate a uniformly distributed number in any range by simply using the supplied functions that operate with ranges. They are designed to not alter the distribution.

If you language or library doesn't have such a function you can use the following formula:

Code:
`min + random() * (max - min + 1)`

However, what I have is a "black box" that will give me the numbers. So I have to do operations on the numbers already given. So assuming, that random() is the black box I am reffering to, I apply the rule you wrote and I got
Code:
```//dimension x y
2 -0.399516 0.87319
2 0.937221 -0.0146251
2 -0.412698 -0.476573
2 -0.871212 0.255872
2 -0.00647544 0.804864
then
2 -2.19855 1.61957
2 1.81166 -1.04388
2 -2.23809 -2.42972
2 -3.61363 -0.232385
2 -1.01943 1.41459```

4. You could use your x-coord to indicate the side and the y-coord to be the coord on that side.
Code:
```if (x < -.5) {      //Left side
bx = -1;
by = y;
}else if (x < 0) { // Top
bx = y;
by = 1;
}else if (x < .5) { // Right
bx = 1;
by = y;
}else {             // Bottom
bx = y;
by = -1;
}```

5. Will the distribution remain uniform then?
Moreover, I am interested in points in 17D, so I would like to generalize this.

6. Originally Posted by std10093
Will the distribution remain uniform then?
Moreover, I am interested in points in 17D, so I would like to generalize this.
It seems obvious that the distribution would remain uniform. If the 2D distro is uniform then each of it's two linear components must be uniform. With one of those uniform components (x), map an equal subset of its range to each side. The other uniform component (y) is used directly to choose a position on that side.

For N dimensional hypercubes, use one dimension to choose an N-1 dimension hyper-side. Use the remaining N-1 dimension values to select a point within the chosen side.

7. I see. Good.