Monte Carlo simulation for deployment of a WSN

Monte carlo simulation based on random sampling to acquire numerical results. Steps of method: define a domain of inputs, generate inputs randomly, perform a deterministic computation and associate the results. Here an example of Monte Carlo simulation for deployment of a WSN. Assume a uniform random process governs the deployment of network. Assume disk sensing model. Assume that the deployment is done on 100m by 100m square 2D region. Example program that Monte Carlo simulation to find out the necessary number for 99% sensing coverage as a function of sensing radius.

import random
import math

def sensor_location(n):
coordinates = []
for i in range(n):
x = random.uniform(0,100)
y = random.uniform(0,100)
return coordinates

def coverage_ratio(sample_count,sensor,radius):
count = 0
location = sensor_location(sensor)
for i in range(sample_count):
xi = random.uniform(0,100)
yi = random.uniform(0,100)
sensed = False
for j in location:
d = math.sqrt( math.pow((xi-j[0]),2)+ math.pow((yi-j[1]),2))
if d <= radius:
sensed = True
if sensed == False:
count += 1
coverage indicates non-sensed area
coverage = ((count/float(sample_count))*10000)
return 100-(coverage/100)

def simulation(sample, sensor, radius):
print "running for radius = %d" % radius
while True:
ratio = coverage_ratio(sample,sensor,radius)
if ratio >= 99.0:
print "number of required sensor: %d" % sensor
print "coverage: %f" % ratio
return ratio

'''perform simulation for
initial sensor = 10
and r = 5 m

def main():

if __name__ == "__main__":

After 15 times running the program, the simulation result shows the average necessary sensor number for 99% sensing coverage is 586.73.