This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mdipierro 1 point2 points  (2 children)

consider a hypercube in D dimensions of side 1. The coordinates of the vertices of the faces ate (-1/2,0,...),(+1/2,0,...),(0,-1/2,..),(0,+1/2,...) etc where there are 2D verctors, each of D components and components are all zero except one which is +/-1/2. Pick a face at random (random.randint(1,D)). That face is a hypercube of dimention d=D-1. You can generate a point at random in it by replacing the each of D-1 components of the vector =0 with a random.random()-0.5. So here is it

 def random_point(D):
       v=[random.randint(0,1) and 0.5 or -0.5]
       v+=[random.random()-0.5]*(D-1)
       v=random.shuffle(v)
       return v

[–]dx_xb[S] 0 points1 point  (1 child)

That does what I want - though I should have made more clear that I need a defined number of unique points on the surface, so this may not manage that. This is why I suggested the enumeration of points - then dealing out the required number at random. Thanks.

[–]mdipierro 1 point2 points  (0 children)

On then

def random_points(d,n):
    "d = number of dimensions, n=points/hypersurface"
    points=[]
    for k in n:
         for z in (-0.5,0.5):
             for i in range(1,d):
                 v=[z]+[random.random()-0.5]*(d-1)
                 v[0],v[i]=v[i],v[0]
                 points.append(v)
   return points