Пример #1
0
/* O(n) */
BI BIrng(BI x) {
	int i;
	BI z = BInew(x.l);
	for (i = 0; i < x.l-1; i++) {
		z.b[i] = WELLRNG512a();
	}
	z.b[z.l-1] = WELLRNG512a() % (1+x.b[x.l-1]);
	return BIfix(z, z.l-1); /* just for sure */
}
Пример #2
0
void	well_random_engine_test()
{
	unsigned int init[1391] = { 0, };
	for( int i = 0; i < sizeof( init )/sizeof( init[0] ); ++i )
	{
		init[i] = rand();
	}
	
	#define MASK32  0xffffffffU
	#define JMAX 16

	init[0] = 123456789;
	for( int i = 1; i < JMAX; ++i )
		init[i] = (663608941 * init[i - 1]) & MASK32;



	InitWELLRNG512a( init );
	InitWELLRNG1024a( init );
	InitWELLRNG19937a( init );
	InitWELLRNG44497a( init );
	g_rand();

	{
		DWORD start = GetTickCount();
		for( int i = 0; i < total_rand_count; ++i )
		{
			double r = g_rand.gen();
			r;
		}
		DWORD runing = GetTickCount() - start;
		std::wcout << L"g_rand run time: " << runing << std::endl;
	}

	{
		DWORD start = GetTickCount();
		for( int i = 0; i < total_rand_count; ++i )
		{
			double r = WELLRNG512a();
			r;
		}
		DWORD runing = GetTickCount() - start;
		std::wcout << L"WELL512 run time: " << runing << std::endl;
	}

	{
		DWORD start = GetTickCount();
		for( int i = 0; i < total_rand_count; ++i )
		{
			double r = WELLRNG1024a();
			r;
		}
		DWORD runing = GetTickCount() - start;
		std::wcout << L"WELL1024 run time: " << runing << std::endl;
	}

	{
		DWORD start = GetTickCount();
		for( int i = 0; i < total_rand_count; ++i )
		{
			double r = WELLRNG19937a();
			r;
		}
		DWORD runing = GetTickCount() - start;
		std::wcout << L"WELL19937 run time: " << runing << std::endl;
	}

	{
		DWORD start = GetTickCount();
		for( int i = 0; i < total_rand_count; ++i )
		{
			double r = WELLRNG44497a();
			r;
		}
		DWORD runing = GetTickCount() - start;
		std::wcout << L"WELL44497 run time: " << runing << std::endl;
	}

}
Пример #3
0
uint64_t rng64() {
	uint64_t a, b;
	a = (uint64_t)WELLRNG512a();
	b = (uint64_t)WELLRNG512a();
	return (a<<32) | b;
}