New function random_range().
authorBen Pfaff <blp@nicira.com>
Wed, 9 Jul 2008 01:40:41 +0000 (18:40 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 18 Jul 2008 20:42:37 +0000 (13:42 -0700)
include/random.h
lib/random.c

index 92e2cb3..d9f5f9d 100644 (file)
@@ -39,5 +39,6 @@
 
 void random_bytes(void *, size_t);
 uint32_t random_uint32(void);
+int random_range(int max);
 
 #endif /* random.h */
index 55507e0..d5d8b95 100644 (file)
@@ -70,3 +70,9 @@ random_uint32(void)
     random_bytes(&x, sizeof x);
     return x;
 }
+
+int
+random_range(int max) 
+{
+    return random_uint32() % max;
+}