Skip to content

Instantly share code, notes, and snippets.

@anthony-y
Last active October 18, 2017 11:15
Show Gist options
  • Save anthony-y/7b164ac2e3614aa5727c to your computer and use it in GitHub Desktop.
Save anthony-y/7b164ac2e3614aa5727c to your computer and use it in GitHub Desktop.
A simple python program to generate pseudo-random coordinates.
import random
class generatecoords:
def __init__(self, maxX, maxY, maxCoords):
self.maxX = maxX
self.maxY = maxY
self.maxCoords = maxCoords
def gen(): # Call this function to generate co-ords in your script.
coordCount = 0
randomX = random.randrange(0, self.maxX) # Generate "x" between 0 and 50 e.g: (35, y)
randomY = random.randrange(0, self.maxY) # Generate "y" between 0 and 50 e.g (x, 46)
while(randomX != self.maxX and randomY != self.maxY):
randomX = random.randrange(0, self.maxX)
randomY = random.randrange(0, self.maxY)
print(randomX, randomY) # Print a single set of co-ordinates e.g: (10, 27)
elif(coordCount == self.maxCoords): # This will generate 10 co-ordinates because the coordCount is iterated at every end of the loop.
print("You can have no more coordinates.\n")
break
coordCount += 1 # Iterate the coordCount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment