library/src/utility/BP-NumberUtilities.cc
// Generates a random unsigned char value (primarily used for packing together
// uuid values)
Generates a random unsigned char value (primarily used for packing together
uuid values)
Generates a random unsigned char value ( primarily used for packing together uuid values )
unsigned char BP_GenerateRandomUChar(unsigned char low_limit, unsigned char high_limit)
{
	BP_SeedPNRG();
	if(!low_limit && !high_limit)
	{
		printf("\n [!!] Attempted to generate a random number between 0 and 0 (only outcome being zero).");
		return 0;
	}
	unsigned char random_item = 0;
#ifdef __GNUC__
	random_item = (unsigned char) 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;
}
unsigned char BP_GenerateRandomUChar ( unsigned char low_limit , unsigned char high_limit ) { BP_SeedPNRG ( ) ; if ( ! low_limit && ! high_limit ) { printf ( " \n " ) ; return 0 ; } unsigned char random_item = 0 ; #ifdef __GNUC__ random_item = ( unsigned char ) 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 unsigned char value (primarily used for packing together
uuid values)
Generates a random unsigned char value ( primarily used for packing together uuid values )
// try to set pnrg if not already set // check to see that parameters are set // 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 random item