home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
6739684
)
Moved seed initialization into rrand().
author
Christian Heller
<c.heller@plomlompom.de>
Sun, 26 May 2013 03:31:44 +0000
(
05:31
+0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Sun, 26 May 2013 03:31:44 +0000
(
05:31
+0200)
roguelike.c
patch
|
blob
|
history
diff --git
a/roguelike.c
b/roguelike.c
index 7b2d159f878b5ea3fa4e5278d5295f5488abbd55..c91c407360c100d71921f82ab39631b1d676197e 100644
(file)
--- a/
roguelike.c
+++ b/
roguelike.c
@@
-8,13
+8,12
@@
#include "roguelike.h"
#include "keybindings.h"
#include "roguelike.h"
#include "keybindings.h"
-static uint32_t seed = 0;
-
uint16_t rrand() {
// Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability.
uint32_t a = 1103515245; // Values for a and b as recommended by POSIX.1-2001 (see man page rand(3)).
uint16_t b = 12345;
uint32_t mod = 2147483648;
uint16_t rrand() {
// Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability.
uint32_t a = 1103515245; // Values for a and b as recommended by POSIX.1-2001 (see man page rand(3)).
uint16_t b = 12345;
uint32_t mod = 2147483648;
+ static uint32_t seed = 0;
seed = ((seed * a) + b) % mod;
return (seed / 65536); } // Ignore least significant 16 bits (they are less random).
seed = ((seed * a) + b) % mod;
return (seed / 65536); } // Ignore least significant 16 bits (they are less random).