diff options
author | brianluau <brianluau@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-12-05 02:53:33 +0000 |
---|---|---|
committer | brianluau <brianluau@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2012-12-05 02:53:33 +0000 |
commit | 60a426c0742b3e7d8c5b557c7578df6eeeea377b (patch) | |
tree | 5d01f9ccc2798309f9b13f07c0096ed97c6a85c8 /src/common/random.c | |
parent | 621db2441f69736a6c8f10d26bf966d5414fac74 (diff) | |
download | hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.gz hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.bz2 hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.tar.xz hercules-60a426c0742b3e7d8c5b557c7578df6eeeea377b.zip |
- Undid r16968: SVN Replaced with source:/trunk/src/@16966 (tid:74924).
[16969:16991/trunk/src/] will be re-committed in the next 24 hours.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16992 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/random.c')
-rw-r--r-- | src/common/random.c | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/common/random.c b/src/common/random.c index ab9b0052f..5c048c7eb 100644 --- a/src/common/random.c +++ b/src/common/random.c @@ -5,10 +5,10 @@ #include "../common/timer.h" // gettick #include "random.h" #if defined(WIN32) -#include "../common/winapi.h" + #include "../common/winapi.h" #elif defined(HAVE_GETPID) || defined(HAVE_GETTID) -#include <sys/types.h> -#include <unistd.h> + #include <sys/types.h> + #include <unistd.h> #endif #include <time.h> // time #include <mt19937ar.h> // init_genrand, genrand_int32, genrand_res53 @@ -17,34 +17,34 @@ /// Initializes the random number generator with an appropriate seed. void rnd_init(void) { - uint32 seed = gettick(); - seed += (uint32)time(NULL); + uint32 seed = gettick(); + seed += (uint32)time(NULL); #if defined(WIN32) - seed += GetCurrentProcessId(); - seed += GetCurrentThreadId(); + seed += GetCurrentProcessId(); + seed += GetCurrentThreadId(); #else #if defined(HAVE_GETPID) - seed += (uint32)getpid(); + seed += (uint32)getpid(); #endif // HAVE_GETPID #if defined(HAVE_GETTID) - seed += (uint32)gettid(); + seed += (uint32)gettid(); #endif // HAVE_GETTID #endif - init_genrand(seed); + init_genrand(seed); } /// Initializes the random number generator. void rnd_seed(uint32 seed) { - init_genrand(seed); + init_genrand(seed); } /// Generates a random number in the interval [0, SINT32_MAX] int32 rnd(void) { - return (int32)genrand_int31(); + return (int32)genrand_int31(); } @@ -52,7 +52,7 @@ int32 rnd(void) /// NOTE: interval is open ended, so dice_faces is excluded (unless it's 0) uint32 rnd_roll(uint32 dice_faces) { - return (uint32)(rnd_uniform()*dice_faces); + return (uint32)(rnd_uniform()*dice_faces); } @@ -60,9 +60,9 @@ uint32 rnd_roll(uint32 dice_faces) /// Returns min if range is invalid. int32 rnd_value(int32 min, int32 max) { - if (min >= max) - return min; - return min + (int32)(rnd_uniform()*(max-min+1)); + if( min >= max ) + return min; + return min + (int32)(rnd_uniform()*(max-min+1)); } @@ -70,7 +70,7 @@ int32 rnd_value(int32 min, int32 max) /// NOTE: interval is open ended, so 1.0 is excluded double rnd_uniform(void) { - return ((uint32)genrand_int32())*(1.0/4294967296.0);// divided by 2^32 + return ((uint32)genrand_int32())*(1.0/4294967296.0);// divided by 2^32 } @@ -79,5 +79,5 @@ double rnd_uniform(void) /// NOTE: 53 bits is the maximum precision of a double double rnd_uniform53(void) { - return genrand_res53(); + return genrand_res53(); } |