Problem with Monte Carlo(integration by rejection)

This program finds the value of π (pi) with the Monte Carlo method.

#1Consiter that unit circle (radious = 1 ) within a square with sides equal to 2.If we pick a random point(x,y) were both x and y are

between -1,........1. the probability that this random point lies

inside the circle is given as the proportion:

**P( x^2 + y^2<1 ) = Area circle/Area square = ( pi )/4 **

#2If we pick a random point N times and M of those times the point lies inside the unit circle ,the probabillity of that a random point lies inside the unit circle is given as:

**P ( x^2 + y^2<1 ) = M/N **

#3 But if N becomes very large (theoretically infinite)the true probabilities #1-#2 tend to became equal

**4M/N=pi**

Can you help me in my problem. I'm new with the programming :)

I want to make drand48() function tou give me values in the interval [-1,1]

and i dont know how....

Code:

`#include<stdio.h>`

#include<stdlib.h>

#define TOTAL_NUM 100000

int m=0,n=0;double x,y,pi;

int main()

{

for(n=0;n<TOTAL_NUM;n++)

{

x=............i need some code here;

y=............also i need some code here;

if((x*x)+(y*y)<1) m++;

}

pi=4.0*m/n;

printf("%lf",pi)

return 0;

}

why i get this error?(Monte carlo method)

This program finds the value of ð (pi) with the Monte Carlo method.

#1Consiter that unit circle (radious = 1 ) within a square with sides equal to 2.If we pick a random point(x,y) were both x and y are

between -1,........1. the probability that this random point lies

inside the circle is given as the proportion:

P( x^2+y^2<1 ) = Area circle/Area square = ( pi )/4

#2If we pick a random point N times and M of those times the point lies inside the unit circle ,the probabillity of that a random point lies inside the unit circle is given as:

P ( x^2+y^2<1 ) = M/N

#3 But if N becomes very large (theoretically infinite)the true probabilities #1-#2 tend to became equal

4M/N=pi

WHY I GET THIS ERROR:undefined reference to `drand48(void)

Code:

`#include<stdio.h> `

#include<stdlib.h>

double x,y,pi,n_counter,count,m;

double drand48(void);

int main()

{

printf("Give N :\n");

scanf("%lf",&n_counter);

for(count=0;count<=n_counter;count++)

{

y=2.0*drand48()-1.0;

x=2.0*drand48()-1.0;

if(x*x+y*y<1)

{

m++;

}

}

pi=4.0*m/n_counter;

printf("Pi =%lf",pi);

return 0;

}