Reputation: 7895
How can i generate random-uniform points in the surface of a N-dimensional cube with edge E?
For the 3D case, it's easy:
1-pick 2 dimensions from x, y, z
2-generate 2 random points
3-generate 0 or 1 for the third-dimension
Can i generalize this for N-dimensions? thanks!
Upvotes: 0
Views: 455
Reputation: 13957
In Java this could look like this:
int dimension = 5;
int number = 10;
Vector<Double> v = new Vector<Double> (dimension);
for (int n = 0; n < number; n++) {
v.clear();
for (int m = 0; m < dimension; m++) v.add(Math.random()); // [0..1]
v.set((int) Math.ceil(Math.random() * dimension) - 1, // random position
Math.ceil(Math.random() * 2) - 1); // 0 or 1
System.out.println("Vector: " + v);
}
Not well optimized, but working ;-)
Cheers!
Upvotes: 1