Repository navigation
feat(util): add createSeededRandom() - #3586
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain, with the change accompanied by documented types and comprehensive coverage for determinism, ranges, swapped bounds, and seed conversion.
No open issues 🎉
What changed in this PR
Adds util.createSeededRandom(seed) to @joint/core, providing deterministic Mulberry32-based pseudo-random sequences with floating-point and inclusive integer-range forms.
Changes:
- Added the seeded random utility with documented seed normalization and overloads.
- Added comprehensive tests for determinism, ranges, swapped bounds, and seed conversion.
- Replaced the duplicated generator in right-angle path tests.
- Added the
@joint/coreminor-release changeset.
| File | Description |
|---|---|
packages/joint-core/types/util.d.ts |
Declares and documents the seeded random factory and callable overloads. |
packages/joint-core/test/jointjs/core/util.js |
Tests deterministic sequences, ranges, swapped bounds, and seed conversion. |
packages/joint-core/test/jointjs/alg.rightAnglePath.js |
Reuses the shared seeded random utility in deterministic tests. |
packages/joint-core/src/util/util.mjs |
Implements the Mulberry32-based seeded random generator. |
.changeset/util-create-seeded-random.md |
Records the minor @joint/core release change. |
Review effort: Lite
MartinKanera
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
util.createSeededRandom(seed). It returns a random function that gives the same sequence for the same seed:random()is a drop-in forMath.random(), andrandom(max)/random(min, max)replaceg.random(max)/g.random(min, max). Code that generates random data needs one random function, with nothing passed into other APIs.1.5acts as1,-1as4294967295, andNaN,Infinityor a non-numeric value as0.g.random(),g.Point.random()) is unchanged.alg.rightAnglePathtests is replaced byutil.createSeededRandom(). It produces the same sequence, so the test cases are unchanged.Refs #3558
Motivation and Context
Demos, examples and tests that generate random positions, sizes or graphs use
Math.random()org.random(), which can't be seeded. They look different on every run, so they can't be compared against reference screenshots, reproduced from a bug report, or tested deterministically.Tests
test/jointjs/core/util.js(util.createSeededRandom()):random()stays within[0, 1);random(max)andrandom(min, max)cover the whole integer range, including swapped bounds;NaNandInfinity.yarn distbuilds.geometry359/359,vectorizer462/462 andjoint2245/2245 pass.yarn test-server,yarn lint,yarn test-tsandyarn test-coveragepass.