如何在N维立方体的表面生成随机均匀点 边缘E?
对于3D情况,这很简单:
1-pick 2 dimensions from x, y, z
2-generate 2 random points
3-generate 0 or 1 for the third-dimension
我可以将其概括为N维吗? 谢谢!
答案 0 :(得分:2)
在Java中,这可能是这样的:
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);
}
没有很好地优化,但正在工作; - )
干杯!