Skip to content

Commit 5f902c2

Browse files
committed
Merge pull request ckknight#10 from pariser/mt-with-index
Add getUseCount() method to mt19937 engine
2 parents 788254e + a9c60d0 commit 5f902c2

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

lib/random.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
function mt19937() {
112112
var data = new Int32Array(624);
113113
var index = 0;
114+
var uses = 0;
114115

115116
function next() {
116117
if ((index | 0) >= 624) {
@@ -120,9 +121,14 @@
120121

121122
var value = data[index];
122123
index = (index + 1) | 0;
124+
uses += 1;
123125
return temper(value) | 0;
124126
}
127+
next.getUseCount = function() {
128+
return uses;
129+
};
125130
next.discard = function (count) {
131+
uses += count;
126132
if ((index | 0) >= 624) {
127133
refreshData(data);
128134
index = 0;
@@ -143,6 +149,7 @@
143149
data[i] = previous = (imul((previous ^ (previous >>> 30)), 0x6c078965) + i) | 0;
144150
}
145151
index = 624;
152+
uses = 0;
146153
return next;
147154
};
148155
next.seedWithArray = function (source) {

spec/engines.mt19937Spec.js

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)