From: VMware, Inc <> Date: Tue, 17 Nov 2009 22:09:01 +0000 (-0800) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2009.11.16-210370~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=874395cef6da41d910d5738cbc70e2ce3316bc2e;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/util.h b/open-vm-tools/lib/include/util.h index 55abf53c2..63c1213c6 100644 --- a/open-vm-tools/lib/include/util.h +++ b/open-vm-tools/lib/include/util.h @@ -156,6 +156,7 @@ Bool Util_QueryCStResidency(uint32 *numCpus, uint32 *numCStates, * In util_shared.h */ EXTERN Bool Util_Throttle(uint32 count); +EXTERN uint32 Util_FastRand(uint32 seed); /* *---------------------------------------------------------------------- diff --git a/open-vm-tools/lib/include/util_shared.h b/open-vm-tools/lib/include/util_shared.h index 80b9389fb..d547947fb 100644 --- a/open-vm-tools/lib/include/util_shared.h +++ b/open-vm-tools/lib/include/util_shared.h @@ -51,6 +51,43 @@ Util_Throttle(uint32 count) count % 1000000 == 0; } +/* + *---------------------------------------------------------------------- + * + * Util_FastRand -- + * + * Generates the next random number in the pseudo-random sequence + * defined by the multiplicative linear congruential generator + * S' = 16807 * S mod (2^31 - 1). + * This is the ACM "minimal standard random number generator". + * Based on method described by D.G. Carta in CACM, January 1990. + * Usage: provide previous random number as the seed for next one. + * + * Precondition: + * 0 < seed && seed < UTIL_FASTRAND_SEED_MAX + * + * Results: + * A random number. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +#define UTIL_FASTRAND_SEED_MAX (0x7fffffff) + +uint32 +Util_FastRand(uint32 seed) +{ + uint64 product = 33614 * (uint64)seed; + uint32 product_lo = (uint32)(product & 0xffffffff) >> 1; + uint32 product_hi = product >> 32; + int32 test = product_lo + product_hi; + ASSERT(0 < seed && seed < UTIL_FASTRAND_SEED_MAX); + return (test > 0) ? test : (test & UTIL_FASTRAND_SEED_MAX) + 1; +} + #if defined(USERLEVEL) || defined(VMX86_DEBUG) static uint32 crcTable[256];