Skip to content

Instantly share code, notes, and snippets.

@kayru
Created April 30, 2012 18:20
Show Gist options
  • Save kayru/2560742 to your computer and use it in GitHub Desktop.
Save kayru/2560742 to your computer and use it in GitHub Desktop.
Generate random points on disc
import sys
import random
def GeneratePointsInsideDisc(num_points) :
points = []
for i in range(num_points) :
while True :
x = random.uniform(-1,1)
y = random.uniform(-1,1)
if( (x*x+y*y) <= 1.0 ) :
points.append([x,y])
break
return points
if len(sys.argv) > 1 :
points = GeneratePointsInsideDisc(int(sys.argv[1]))
print "float2 points[] = \n{"
for i in range(len(points)) :
print "\tfloat2(%(x).03f, %(y).03f)," % {"x":points[i][0], "y":points[i][1]}
print "};"
else:
print "Usage: generate_points_inside_disc.py <num_points>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment