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 ; 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
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public class store : IComparer < KeyValuePair < int , int > > { public int Compare ( KeyValuePair < int , int > x , KeyValuePair < int , int > y ) { if ( x . Key != y . Key ) { return x . Key . CompareTo ( y . Key ) ; } else { return x . Value . CompareTo ( y . Value ) ; } } } static void generatePoints ( int L , int W ) { SortedSet < KeyValuePair < int , int > > hash = new SortedSet < KeyValuePair < int , int > > ( new store ( ) ) ; int total = ( L * W ) ; Random rand = new Random ( ) ; while ( ( total -- ) != 0 ) { int X = rand . Next ( ) % L ; int Y = rand . Next ( ) % W ; while ( hash . Contains ( new KeyValuePair < int , int > ( X , Y ) ) ) { X = rand . Next ( ) % L ; Y = rand . Next ( ) % W ; } hash . Add ( new KeyValuePair < int , int > ( X , Y ) ) ; } foreach ( KeyValuePair < int , int > x in hash ) { Console . Write ( " ( " + x . Key + " , ▁ " + x . Value + " ) ▁ " ) ; } } public static void Main ( string [ ] args ) { int L = 3 , W = 2 ; generatePoints ( L , W ) ; } }