mitsuba-af602c6fd98a/src/tests/test_random.cpp
// Simple Monte Carlo estimation of the area of a circle of radius 0.5
Simple Monte Carlo estimation of the area of a circle of radius 0.5
Simple Monte Carlo estimation of the area of a circle of radius 0 . 5
void TestRandom::test03_circle()
{
	ref<Random> rnd = new Random;
	int hit = 0;
	const int N = 10000000;
	for (int i = 0; i < N; ++i) {
		const Float dx = rnd->nextFloat() - 0.5f;
		const Float dy = rnd->nextFloat() - 0.5f;
		if (dx*dx + dy*dy <= 0.25f) {
			++hit;
		}
	}
	const Float area = static_cast<Float>(hit) / N;
	assertEqualsEpsilon(area, 0.25f * M_PI, 1e-4f);
}
void TestRandom :: test03_circle ( ) { ref < Random > rnd = new Random ; int hit = 0 ; const int N = 10000000 ; for ( int i = 0 ; i < N ; ++ i ) { const Float dx = rnd -> nextFloat ( ) - 0.5f ; const Float dy = rnd -> nextFloat ( ) - 0.5f ; if ( dx * dx + dy * dy <= 0.25f ) { ++ hit ; } } const Float area = static_cast < Float > ( hit ) / N ; assertEqualsEpsilon ( area , 0.25f * M_PI , 1e-4f ) ; }
Simple Monte Carlo estimation of the area of a circle of radius 0.5
Simple Monte Carlo estimation of the area of a circle of radius 0 . 5