Urgent.News

What's breaking now, across hundreds of outlets.

Tech

For random numbers on the GPU, encrypt a counter

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.

Rewritten by urgent.news; may contain errors — check the original. How we use AI.

Source: klauria.tech

Read the original at klauria.tech →

Get the news by email. Yesterday's most-covered stories, every morning.

We track opens and clicks to improve the newsletter.

See today's edition · More options

More in Tech

EVs outsell gas cars in the EU over a full year for the first time

According to Ember's Electric Vehicle Sales Data Tracker, 2.6 million new fully electric cars were registered in the EU in the 12 months to October 2026, accounting for 23% of the market. Over the same period, gas car registrations fell 20% to 2.5 million, representing around 22% of all new car sales. Read Entire Article

More from Sunday, 6 December 2026 →