{
  "id": 23852182,
  "title": "For random numbers on the GPU, encrypt a counter",
  "url": "https://urgent.news/2026/12/06/for-random-numbers-on-the-gpu-encrypt-a-counter",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-06T15:03:52.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://klauria.tech/for-random-numbers-on-the-gpu-encrypt-a-counter/"
  },
  "original_language": null,
  "account": "If you are generating random numbers on a GPU, it is recommended to avoid RNGs with internal state that updates for every number produced. Instead, opt for stateless RNGs that encrypt or hash a counter. This approach, popular in many machine learning frameworks and libraries, offers several advantages. By using a counter-based RNG, each GPU thread can generate its own sequence of random numbers without needing to read or write VRAM. This avoids stalls caused by memory operations and reduces the amount of state required. However, there are situations where counter-based RNGs may not be the best choice. They consume more computation, so if your benchmarks indicate compute-bound tasks, it might be better to allocate memory to save compute. In some cases, such as when using WGSL or initializing an RNG for a single kernel launch, persisting state in memory may be unnecessary. The demos provided in this article compare stateful RNGs (XORWOW), counter-based RNGs with VRAM storage, and stateless RNGs without stored state. While stateless RNGs don't always outperform others, they offer memory efficiency. Keep in mind that performance may vary depending on your hardware and browser implementation. Counter-based RNGs are particularly useful in machine learning tasks, where random numbers are extensively used in inference, training, augmentation, diffusion models, reinforcement learning, and more. The path tracer demo showcases the benefits of counter-based RNGs in physically based rendering, where multiple random numbers are needed for each pixel. The article also highlights the use of random numbers in physics simulations, Bayesian model sampling, and frontend design.",
  "summary": null,
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}