]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Tue, 17 Nov 2009 22:09:01 +0000 (14:09 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 17 Nov 2009 22:09:01 +0000 (14:09 -0800)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/include/util.h
open-vm-tools/lib/include/util_shared.h

index 55abf53c29e593879d6ef4822e058a0af024d538..63c1213c65518cb9c91acf4772fea2591ff8d450 100644 (file)
@@ -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);
 
 /*
  *----------------------------------------------------------------------
index 80b9389fb23b20d22c7c4661b6d9dbf54581e9aa..d547947fb9b33b9b50d39902e17dc4b1335769e8 100644 (file)
@@ -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];