library/src/utility/BP-NumberUtilities.cc
// generates a random number between the low limit and high limit
// This implementation uses the system entropy pool in order to generate
// any number versus using rand().  This improves randomness, but does
// add overhead.  This is linux only
generates a random number between the low limit and high limit
This implementation uses the system entropy pool in order to generate
any number versus using rand().  This improves randomness, but does
add overhead.  This is linux only
generates a random number between the low limit and high limit This implementation uses the system entropy pool in order to generate any number versus using rand () . This improves randomness but does add overhead . This is linux only
size_t BP_GenRandomUnsignedLong(size_t low_limit, size_t high_limit)
{
	BP_SeedPNRG();
	if(!low_limit && !high_limit)
	{
		return 0;
	}
	size_t random_item = 0;
#ifdef __GNUC__
	random_item = (size_t) rand();
	if((low_limit == 0) && (high_limit == 1))
	{
		 as a bitshift
		random_item = (random_item & (1 << 0));
		return random_item;
	}
	random_item = (random_item % high_limit) + low_limit;
	if(random_item > high_limit)
		random_item -= low_limit;
#endif
#ifndef __GNUC__
	printf("\n TODO: IMPLEMENT SYSTEM ENTROPY RANDOM NUM GEN ON WIN32.");
#endif
	return random_item;
}
size_t BP_GenRandomUnsignedLong ( size_t low_limit , size_t high_limit ) { BP_SeedPNRG ( ) ; if ( ! low_limit && ! high_limit ) { return 0 ; } size_t random_item = 0 ; #ifdef __GNUC__ random_item = ( size_t ) rand ( ) ; if ( ( low_limit == 0 ) && ( high_limit == 1 ) ) { random_item = ( random_item & ( 1 << 0 ) ) ; return random_item ; } random_item = ( random_item % high_limit ) + low_limit ; if ( random_item > high_limit ) random_item -= low_limit ; #endif #ifndef __GNUC__ printf ( " \n " ) ; #endif return random_item ; }
generates a random number between the low limit and high limit
This implementation uses the system entropy pool in order to generate
any number versus using rand().
generates a random number between the low limit and high limit This implementation uses the system entropy pool in order to generate any number versus using rand () .
// try to set pnrg if not already set // check to see that parameters are set // printf("\n [!!] Attempted to generate a random number between 0 and 0 (only outcome being zero)."); // set the random item // set random item from rand // if we're doing a binary generation, we can just bitshift for our answer // set the random item as a bitshift // set the random item // subtract lowlimit from top in case number is too high // return the new 4 byte value