Skip to content

Commit 503d398

Browse files
committed
use xorshift
1 parent 93489f7 commit 503d398

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

test/test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import assert from 'assert';
44
import { String_random } from '../lib/String_random.js';
55
import test from 'node:test';
66

7-
// シード付き乱数生成器
7+
// シード付き乱数生成器(Xorshift32)
88
function seededRandom(seed) {
9-
let x = Math.sin(seed) * 10000;
9+
let x = seed >>> 0;
1010
return function() {
11-
x = Math.sin(x) * 10000;
12-
return x - Math.floor(x);
11+
// Xorshift32アルゴリズム
12+
x ^= x << 13;
13+
x ^= x >>> 17;
14+
x ^= x << 5;
15+
return (x >>> 0) / 0x100000000;
1316
};
1417
}
1518
const random = seededRandom(42);

0 commit comments

Comments
 (0)