Generate all integral points lying inside a rectangle | C ++ 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 ; Use current time as seed for random generator ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void generatePoints ( int L , int W ) { set < pair < int , int > > hash ; int total = ( L * W ) ; srand ( time ( 0 ) ) ; while ( total -- ) { int X = rand ( ) % L ; int Y = rand ( ) % W ; while ( hash . count ( { X , Y } ) ) { X = rand ( ) % L ; Y = rand ( ) % W ; } hash . insert ( { X , Y } ) ; } for ( auto points : hash ) { cout << " ( " << points . first << " , ▁ " << points . second << " ) ▁ " ; } } int main ( ) { int L = 3 , W = 2 ; generatePoints ( L , W ) ; }