Add atest and adjust mulberry32
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
import { expect, test } from "vitest";
|
||||||
|
import { mulberry32 } from "./mulberry32.ts";
|
||||||
|
|
||||||
|
test("mulberry32", () => {
|
||||||
|
const nextA = mulberry32(1);
|
||||||
|
const nextA2 = mulberry32(1);
|
||||||
|
const nextB = mulberry32(2);
|
||||||
|
const a1 = nextA();
|
||||||
|
|
||||||
|
expect(a1).toBe(0.6270739405881613);
|
||||||
|
expect(nextA2()).toBe(a1);
|
||||||
|
expect(nextA()).not.toBe(a1);
|
||||||
|
expect(nextB()).not.toBe(a1);
|
||||||
|
});
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @see https://github.com/cprosche/mulberry32
|
* @see https://github.com/cprosche/mulberry32
|
||||||
*/
|
*/
|
||||||
export function mulberry32(a: number) {
|
export function mulberry32(a: number): () => number {
|
||||||
return () => {
|
return () => {
|
||||||
a |= 0;
|
a |= 0;
|
||||||
a = (a + 0x6d2b79f5) | 0;
|
a = (a + 0x6d2b79f5) | 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user