2 * Copyright 2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
8 #ifndef KERNEL_UTIL_RANDOM_H
9 #define KERNEL_UTIL_RANDOM_H
13 #include <SupportDefs.h>
16 #define MAX_FAST_RANDOM_VALUE 0x7fff
17 #define MAX_RANDOM_VALUE 0x7fffffffu
18 #define MAX_SECURE_RANDOM_VALUE 0xffffffffu
20 static const int kFastRandomShift
= 15;
21 static const int kRandomShift
= 31;
22 static const int kSecureRandomShift
= 32;
28 unsigned int fast_random_value(void);
29 unsigned int random_value(void);
30 unsigned int secure_random_value(void);
45 while (shift
< sizeof(T
) * 8) {
46 random
|= (T
)fast_random_value() << shift
;
47 shift
+= kFastRandomShift
;
60 while (shift
< sizeof(T
) * 8) {
61 random
|= (T
)random_value() << shift
;
62 shift
+= kRandomShift
;
75 while (shift
< sizeof(T
) * 8) {
76 random
|= (T
)secure_random_value() << shift
;
77 shift
+= kSecureRandomShift
;
86 #endif // KERNEL_UTIL_RANDOM_H