Last active
October 18, 2017 11:15
-
-
Save anthony-y/7b164ac2e3614aa5727c to your computer and use it in GitHub Desktop.
A simple python program to generate pseudo-random coordinates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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