[p5.js 2.0+ Bug Report]: randomGaussian() leaks its spare value across p5 instances, breaking seeded determinism
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript
- 领域
- frontend
调研方向
从 src/math/random.js 开始,检查现有的、被跳过的实例模式独立性测试。使用两个 p5 实例重现交错的带种子调用,然后运行相关的随机数测试。完成的标准是这些实例产生相互独立的确定性序列,并且回归测试通过。
由索引模型根据 Issue 内容生成。
描述
Most appropriate sub-area of p5.js?
Math
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
The randomSeed() reference promises that a constant seed "makes these functions produce the same results each time a sketch is run", explicitly naming randomGaussian(). That breaks as soon as two p5 instances exist on a page.
randomGaussian() uses the Marsaglia polar method, which produces values in pairs. The flag that says "a spare value is cached" lives on the instance (this._gaussian_previous), but the spare value itself lives in module scope (let y2 = 0; in src/math/random.js). With two instances, B's spare overwrites A's, and A's next call returns B's value.
Executed repro (both instances seeded, one interleaved call on instance B):
A alone : -0.2050, -0.3410, 0.3986, -1.4309
A interleaved: -0.2050, -0.9404, 0.3986, -1.4309
Same seed, different sequence. The existing test suite even contains a skipped "instance mode / should be independent" block asserting exactly this independence. PR #1681 (2015) made _gaussian_previous per-instance but left y2 module-scoped, which is the remaining half of that fix.
Steps to reproduce
Outputs above are from executed runs against main, two instances sharing the prototype as in instance mode.
Note
I have a fix ready (store the spare as this._gaussian_y2) with a regression test, mutation-tested against main. Filing for approval first per the contributing guide; will open the PR once approved.
- 主要语言
- JavaScript
- 星标
- 24.1k
- 派生
- 3.9k
- 平均合并
- 3 天 4 小时
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
processing/p5.js 的其他 Issue
-
Add unit tests for noiseDetail()可能已有人在做 @harshiltewari2004 今天认领。 未关闭Area:Math Enhancement
难度 2/5 1-3 小时 新手友好度 75/100
processing/p5.js#9253 · 2 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: storeItem() validation branches are missing `return`, so bad input throws a TypeError or is stored anyway可能已有人在做 @iUjjwalRaj 于 8 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 85/100
processing/p5.js#9242 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: getURLParams() mis-parses valueless parameters and never percent-decodes values可能已有人在做 @mayanksingh-7974 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
processing/p5.js#9241 · 1 条评论 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: Typo in Spanish reference documentation for ellipseMode()可能重新可做 @cgutierrezval 于 11 天前认领,目前没有进行中的 PR。 未关闭Internationalization p5.js 2.0+
难度 1/5 1 小时以内 新手友好度 95/100
processing/p5.js#9231 · 3 条评论 ·
维护者通常 2 天内回复
-
[p5.js 2.0+ Bug Report]: ReferenceError: p5 is not defined when calling loadPixels/get/copy/mask on p5.MediaElement in ESM可能已有人在做 @Pcmhacker-piro 于 16 天前认领。 未关闭Area:Core Area:DOM
难度 2/5 1-3 小时 新手友好度 86/100
processing/p5.js#9189 · 1 条评论 ·
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
t0ggles
难度 2/5 1-3 小时 新手友好度 70/100
nolimits4web/swiper#8240 · 1 条评论 ·
-
netbox status: backlog topic: testing type: housekeeping
难度 2/5 1-3 小时 新手友好度 70/100
netbox-community/netbox#23395 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
[scanner] check:spelling skips blog/ — posts and author metadata are never spell-checked可能已有人在做 @hivecommons-hive 今天认领。 未关闭agent/scanner bug hive/covered-by-pr hive/hosted-available-lke648397-260827-5n31
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复