From 9441e09d07cad426e4c69ec03a2fc5bbd1e3834a Mon Sep 17 00:00:00 2001 From: kolaflash Date: Wed, 14 Jan 2026 22:00:31 +0100 Subject: [PATCH] Add mulberry32 --- dev/GraphBrowser.tsx | 5 ++++- dev/main.tsx | 2 +- lib/mulberry32.ts | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 lib/mulberry32.ts diff --git a/dev/GraphBrowser.tsx b/dev/GraphBrowser.tsx index d4ec297..afd8843 100644 --- a/dev/GraphBrowser.tsx +++ b/dev/GraphBrowser.tsx @@ -7,6 +7,7 @@ import { getNeighbours, type Node, } from "#/lib/Graph.ts"; +import { mulberry32 } from "#/lib/mulberry32.ts"; import { createVector, getDistance, @@ -119,8 +120,10 @@ function hookEdge([a, b]: Edge): void { export const GraphBrowser: Component<{ graph: Graph; + seed: number; }> = (props) => { let canvasRef!: HTMLCanvasElement; + const next = mulberry32(props.seed); const [width] = createSignal(300); const [height] = createSignal(300); @@ -128,7 +131,7 @@ export const GraphBrowser: Component<{ const enhanceNode = (node: string) => { return { name: node, - position: createVector(Math.random() * 128 - 64, Math.random() * 32 - 16), + position: createVector(next() * 128 - 64, next() * 32 - 16), velocity: createVector(), acceleration: createVector(), }; diff --git a/dev/main.tsx b/dev/main.tsx index e77a7d6..dfe9569 100644 --- a/dev/main.tsx +++ b/dev/main.tsx @@ -182,7 +182,7 @@ const DevTools: Component<{ gameContainer: HTMLElement }> = ({ - + diff --git a/lib/mulberry32.ts b/lib/mulberry32.ts new file mode 100644 index 0000000..0cc4db4 --- /dev/null +++ b/lib/mulberry32.ts @@ -0,0 +1,12 @@ +/** + * @see https://github.com/cprosche/mulberry32 + */ +export function mulberry32(a: number) { + return () => { + a |= 0; + a = (a + 0x6d2b79f5) | 0; + let t = Math.imul(a ^ (a >>> 15), 1 | a); + t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; + return ((t ^ (t >>> 14)) >>> 0) / 4294967296; + }; +}