Find N random points within a Circle | C # program for the above approach ; Return a random double between 0 & 1 ; Function to find the N random points on the given circle ; Result vector ; Get Angle in radians ; Get length from center ; Add point to results . ; Return the N points ; Function to display the content of the vector A ; Iterate over A ; Print the N random points stored ; Driver Code ; Given dimensions ; Function call
using System ; using System . Collections . Generic ; class GFG { static readonly double PI = 3.141592653589 ; class pair { public double first , second ; public pair ( double first , double second ) { this . first = first ; this . second = second ; } } static double uniform ( ) { return new Random ( ) . NextDouble ( ) ; } static List < pair > randPoint ( int r , int x , int y , int n ) { List < pair > res = new List < pair > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { double theta = 2 * PI * uniform ( ) ; double len = Math . Sqrt ( uniform ( ) ) * r ; res . Add ( new pair ( x + len * Math . Cos ( theta ) , y + len * Math . Sin ( theta ) ) ) ; } return res ; } static void printList ( List < pair > A ) { foreach ( pair P in A ) { Console . Write ( " ( { 0 : F2 } , ▁ { 1 : F2 } ) STRNEWLINE " , P . first , P . second ) ; } } public static void Main ( String [ ] args ) { int R = 12 ; int X = 3 ; int Y = 3 ; int N = 5 ; printList ( randPoint ( R , X , Y , N ) ) ; } }