mirror of
https://review.haiku-os.org/haiku
synced 2025-01-20 05:21:28 +01:00
util: style fixes
This commit is contained in:
parent
d9fa99bb60
commit
69042ecd1b
@ -16,8 +16,8 @@
|
||||
#define MAX_FAST_RANDOM_VALUE 0x7fff
|
||||
#define MAX_RANDOM_VALUE 0x7fffffffu
|
||||
|
||||
const int kFastRandomShift = 15;
|
||||
const int kRandomShift = 31;
|
||||
static const int kFastRandomShift = 15;
|
||||
static const int kRandomShift = 31;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <OS.h>
|
||||
|
||||
|
||||
static uint32 fast_last = 0;
|
||||
static uint32 last = 0;
|
||||
static uint32 sFastLast = 0;
|
||||
static uint32 sLast = 0;
|
||||
|
||||
// In the following functions there are race conditions when many threads
|
||||
// attempt to update static variable last. However, since such conflicts
|
||||
@ -24,11 +24,11 @@ static uint32 last = 0;
|
||||
unsigned int
|
||||
fast_random_value()
|
||||
{
|
||||
if (fast_last == 0)
|
||||
fast_last = system_time();
|
||||
if (sFastLast == 0)
|
||||
sFastLast = system_time();
|
||||
|
||||
uint32 random = fast_last * 1103515245 + 12345;
|
||||
fast_last = random;
|
||||
uint32 random = sFastLast * 1103515245 + 12345;
|
||||
sFastLast = random;
|
||||
return (random >> 16) & 0x7fff;
|
||||
}
|
||||
|
||||
@ -39,16 +39,16 @@ fast_random_value()
|
||||
unsigned int
|
||||
random_value()
|
||||
{
|
||||
if (last == 0)
|
||||
last = system_time();
|
||||
if (sLast == 0)
|
||||
sLast = system_time();
|
||||
|
||||
uint32 hi = last / 127773;
|
||||
uint32 lo = last % 127773;
|
||||
uint32 hi = sLast / 127773;
|
||||
uint32 lo = sLast % 127773;
|
||||
|
||||
int32 random = 16807 * lo - 2836 * hi;
|
||||
if (random <= 0)
|
||||
random += MAX_RANDOM_VALUE;
|
||||
last = random;
|
||||
sLast = random;
|
||||
return random % (MAX_RANDOM_VALUE + 1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user