/* Only create a directory if we didn't find one above. */
if (!found) {
- void *p;
+ rqContext *context;
- p = Random_QuickSeed((unsigned)time(NULL));
+ context = Random_QuickSeed((unsigned)time(NULL));
for (i = 0; i < 10; i++) {
Unicode temp;
/* Each staging directory is given a random name. */
Unicode_Free(ret);
- temp = Unicode_Format("%08x%c", Random_Quick(p), DIRSEPC);
+ temp = Unicode_Format("%08x%c", Random_Quick(context), DIRSEPC);
ASSERT_MEM_ALLOC(temp);
ret = Unicode_Append(root, temp);
Unicode_Free(temp);
}
}
- free(p);
+ free(context);
}
exit:
FileSimpleRandom(void)
{
static Atomic_Ptr atomic; /* Implicitly initialized to NULL. --mbellon */
- char *context;
+ rqContext *context;
context = Atomic_ReadPtr(&atomic);
if (UNLIKELY(context == NULL)) {
- void *p;
+ rqContext *newContext;
uint32 value;
/*
value = getpid();
#endif
- p = Random_QuickSeed(value);
+ newContext = Random_QuickSeed(value);
- if (Atomic_ReadIfEqualWritePtr(&atomic, NULL, p)) {
- free(p);
+ if (Atomic_ReadIfEqualWritePtr(&atomic, NULL, (void *) newContext)) {
+ free(newContext);
}
context = Atomic_ReadPtr(&atomic);
#include "vm_basic_types.h"
-
Bool
Random_Crypto(unsigned int size, // IN
void *buffer); // OUT
/*
- * High quality random number generator.
+ * High quality - research grade - random number generator.
+ *
+ * Despite its apparent complexity this RNG is extremely fast.
*/
-void *
-Random_QuickSeed(uint32 seed); // IN
+typedef struct rqContext rqContext;
+
+rqContext *
+Random_QuickSeed(uint32 seed);
uint32
-Random_Quick(void *context);
+Random_Quick(rqContext *context);
+
+/*
+ * Simple multiplicative conguential RNG.
+ */
int
Random_Simple(int seed);
* Side Effects:
* None
*
+ * NOTE:
+ * Despite the look of the code this RNG is extremely fast.
+ *
*-----------------------------------------------------------------------------
*/
#define C 0xDB8B0000
#define L 16
-struct rngstate {
+struct rqContext {
uint32 x[N];
int p, q;
};
-void *
+rqContext *
Random_QuickSeed(uint32 seed) // IN:
{
- struct rngstate *rs;
+ struct rqContext *rs;
const uint32 xx[N] = {
0x95F24DAB, 0x0B685215, 0xE76CCAE7, 0xAF3EC239, 0x715FAD23,
0x512C0C03, 0xEA857CCD, 0x4CC1D30F, 0x8891A8A1, 0xA6B7AADB
};
- rs = (struct rngstate *) malloc(sizeof *rs);
+ rs = (struct rqContext *) malloc(sizeof *rs);
if (rs != NULL) {
uint32 i;
rs->q = N - M - 1;
}
- return (void *) rs;
+ return rs;
}
* Side Effects:
* The RNG context is modified for later use by Random_Quick.
*
+ * NOTE:
+ * Despite the look of the code this RNG is extremely fast.
+ *
*-----------------------------------------------------------------------------
*/
uint32
-Random_Quick(void *context) // IN/OUT:
+Random_Quick(rqContext *rs) // IN/OUT:
{
uint32 y, z;
- struct rngstate *rs = (struct rngstate *) context;
-
- ASSERT(context);
+ ASSERT(rs);
if (rs->p == N - 1) {
rs->p = 0;
*
* Random_Simple --
*
- * Lifted from Util_FastRand() in
- * /vmkernel-main/bora/vmcore/vmm/main/util_monitor.c The header
- * comment of 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.
+ * Generates the next random number in the pseudo-random sequence
+ * defined by the multiplicative linear congruential generator
+ * S' = 33614 * 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.
*
* Results:
- * A random integrer number is returned.
+ * A random integer number is returned.
*
* Side Effects:
* None.
int
Random_Simple(int seed) // IN:
{
- uint64 product = 33614 * (uint64)seed;
- uint32 product_lo = (uint32)(product & 0xFFFFFFFF) >> 1;
+ uint64 product = 33614 * (uint64) seed;
+ uint32 product_lo = (uint32) (product & 0xFFFFFFFF) >> 1;
uint32 product_hi = product >> 32;
int32 test = product_lo + product_hi;