Example #1
0
unsigned long httpfetch_caller_alloc_secure()
{
	MutexAutoLock lock(g_httpfetch_mutex);

	// Generate random caller IDs and make sure they're not
	// already used or equal to HTTPFETCH_DISCARD
	// Give up after 100 tries to prevent infinite loop
	u8 tries = 100;
	unsigned long caller;

	do {
		caller = (((u64) g_callerid_randomness.next()) << 32) |
				g_callerid_randomness.next();

		if (--tries < 1) {
			FATAL_ERROR("httpfetch_caller_alloc_secure: ran out of caller IDs");
			return HTTPFETCH_DISCARD;
		}
	} while (g_httpfetch_results.find(caller) != g_httpfetch_results.end());

	verbosestream << "httpfetch_caller_alloc_secure: allocating "
		<< caller << std::endl;

	// Access element to create it
	g_httpfetch_results[caller];
	return caller;
}
Example #2
0
int myrand_range(int min, int max)
{
    return g_pcgrand.range(min, max);
}
Example #3
0
void myrand_bytes(void *out, size_t len)
{
    g_pcgrand.bytes(out, len);
}
Example #4
0
void mysrand(unsigned int seed)
{
    g_pcgrand.seed(seed);
}
Example #5
0
u32 myrand()
{
    return g_pcgrand.next();
}