Skip to content

[WIP] feat (@typegpu/noise): LCG generator#2215

Open
cieplypolar wants to merge 141 commits intomainfrom
docs/lcg
Open

[WIP] feat (@typegpu/noise): LCG generator#2215
cieplypolar wants to merge 141 commits intomainfrom
docs/lcg

Conversation

@cieplypolar
Copy link
Copy Markdown
Collaborator

@cieplypolar cieplypolar commented Feb 24, 2026

Changes:

  • utility functions in @typegpu/noise (hash, u32To01F32)
  • improved LCG32
  • improved example for benchmarking PRNGs (uniformity)
  • xoroshiro64++ PRNG from chaos master
  • withPerformanceCallback and withTimestampWrites on guardedComputePipeline
  • simulating 64 bits numbers
  • lcg64

TODO:

  • warning of absent seed functions
  • include diagram of 64 bits numbers simulation
  • include test suite for 64 bits operations (probably cpp)
  • update docs
  • optimize u64Mul

* Naive Linear Congruential Generator (LCG)
*/
export const LCG: StatefulGenerator = (() => {
const seed = tgpu.privateVar(d.u32);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue this seed size is not going to be enough for any application with > 1M elements. The reason is simply that your whole internal random state is only ~4B so its going to have a lot of repetition, no matter how good the hashing function is.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. This was part of earlier research. We ended up sticking with the current PRNG but figured that we'd include LCG in docs section about creating your own PRNG. Ultimately, LCG landed in noise package in this PR without much thinking about its performance 🙈. I'll update it to use larger seed and put xoroshiro64++ next to it 🫡

@cieplypolar cieplypolar changed the title feat (@typegpu/noise): LCG generator [WIP] feat (@typegpu/noise): LCG generator Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants