summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/asg.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2013-10-06 17:16:52 +0200
committerAdam Borowski <kilobyte@angband.pl>2013-10-06 17:18:39 +0200
commitba44991f064c3db2626e787dc95d0719877c89b0 (patch)
tree1d3aefaa14238ddbe0d4294e848b740af68607f0 /crawl-ref/source/asg.cc
parentc47ee9af642d5ad698871c7ce31e5ffae6a51d98 (diff)
downloadcrawl-ref-ba44991f064c3db2626e787dc95d0719877c89b0.tar.gz
crawl-ref-ba44991f064c3db2626e787dc95d0719877c89b0.zip
random3(), with a different RNG state.
Works same as random2(). Also, stops valgrind from kvetching about unfreed asg state.
Diffstat (limited to 'crawl-ref/source/asg.cc')
-rw-r--r--crawl-ref/source/asg.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/crawl-ref/source/asg.cc b/crawl-ref/source/asg.cc
index ddf4dbdda5..c612796a6e 100644
--- a/crawl-ref/source/asg.cc
+++ b/crawl-ref/source/asg.cc
@@ -9,7 +9,7 @@
#include "AppHdr.h"
#include "asg.h"
-static AsgKISS* asg_rng = new AsgKISS();
+static AsgKISS asg_rng[2];
uint32_t
AsgKISS::get_uint32()
@@ -58,13 +58,25 @@ AsgKISS::AsgKISS(uint32_t init_key[], int key_length)
}
}
-uint32_t get_uint32()
+uint32_t get_uint32(int generator)
{
- return asg_rng->get_uint32();
+ return asg_rng[generator].get_uint32();
}
void seed_asg(uint32_t seed_array[], int seed_len)
{
- delete asg_rng;
- asg_rng = new AsgKISS(seed_array, seed_len);
+ {
+ const AsgKISS seeded(seed_array, seed_len);
+ asg_rng[0] = seeded;
+ }
+
+ // Use the just seeded RNG to initialize the rest.
+ for (size_t i = 1; i < ARRAYSZ(asg_rng); ++i)
+ {
+ uint32_t key[5];
+ for (size_t j = 0; j < ARRAYSZ(key); ++j)
+ key[j] = asg_rng[0].get_uint32();
+ const AsgKISS seeded(key, ARRAYSZ(key));
+ asg_rng[i] = seeded;
+ }
}