import random
import math


def buffon(needlesNbr, groovesLen, needlesLen):
	"""Simulates Buffon's needle experiments."""

	intersects = 0
	for i in range(needlesNbr):
		y = random.random() * needlesLen / 2
		angle = random.random() * math.pi
		z = groovesLen / 2 * math.sin(angle)

		if y <= z:
			intersects += 1

	expFreq = intersects / needlesNbr
	thFreq = 2 * needlesLen / (math.pi * groovesLen)

	return (intersects, expFreq, thFreq)