]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/libkern/random.c
xnu-4570.51.1.tar.gz
[apple/xnu.git] / bsd / libkern / random.c
index cb2b6ec9d68cece8c6f030c303a44ca272d3b9e5..070080f90afe102c541498ef29634f06297703d6 100644 (file)
 
 #include <sys/types.h>
 #include <sys/random.h>
+#include <libkern/libkern.h>
+#include <dev/random/randomdev.h>
 
 /*
  * Pseudo-random number generator for randomizing the profiling clock,
  * and whatever else we might use it for.  The result is uniform on
  * [0, 2^31 - 1].
  */
-u_long
-random()
+u_int32_t
+random(void)
 {
-       return RandomULong();
+       /* Zero all but bottom 31 bits, also works for 64-bit longs */
+       u_int32_t mask = (u_int32_t)-1 >> ((sizeof(u_int32_t) * 8) - 31);
+       return (mask & RandomULong());
 }