Generate all integral points lying inside a rectangle | Python3 program to implement the above approach ; Function to generate coordinates lying within the rectangle ; Store all possible coordinates that lie within the rectangle ; Stores the number of possible coordinates that lie within the rectangle ; Generate all possible coordinates ; Generate all possible X - coordinates ; Generate all possible Y - coordinates ; If coordinates ( X , Y ) has not been generated already ; Insert the coordinates ( X , Y ) ; Print the coordinates ; Driver code ; Rectangle dimensions
import time NEW_LINE import random NEW_LINE random . seed ( time . time ( ) ) NEW_LINE def generatePoints ( L , W ) : NEW_LINE INDENT hash = { } NEW_LINE total = ( L * W ) NEW_LINE for i in range ( total ) : NEW_LINE INDENT X = random . randint ( 0 , L ) % L NEW_LINE Y = random . randint ( 0 , W ) % W NEW_LINE while ( ( X , Y ) in hash ) : NEW_LINE INDENT X = random . randint ( 0 , L ) % L NEW_LINE Y = random . randint ( 0 , W ) % W NEW_LINE DEDENT hash [ ( X , Y ) ] = 1 NEW_LINE DEDENT for points in sorted ( hash ) : NEW_LINE INDENT print ( " ( " , points [ 0 ] , " , ▁ " , points [ 1 ] , " ) ▁ " , end = " " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT L , W = 3 , 2 NEW_LINE generatePoints ( L , W ) NEW_LINE DEDENT