logoalt Hacker News

For random numbers on the GPU, encrypt a counter

38 points • by evakhoury • last Wednesday at 7:25 PM • 24 comments • view on HN

Comments

Agingcoder • today at 10:52 PM

This idea is a lot older than 2011. I’ve seen it in production systems from 2001-2002 ( and it’s still in use in these systems today ), in an engineering context.

If anything I’m surprised anyone would claim it as original in 2011.

blintz • today at 7:02 PM

If you ever need a lot of cryptographically random numbers on the GPU, you can do cool lattice stuff to do high throughput PRF evaluation. Basically, you can use ‘learning with rounding’ (https://latticeassumptionzoo.org/lwr/) to make the RNG (mostly) a big matmul, which GPUs are great at. This needs to use integers, so Hopper is way better than Blackwell for it. It’s also probably not better than AES in most cases (bc of available intrinsics), but it is way more fun.

blaaarg123 • today at 8:03 PM

> prefer a stateless RNG that works by encrypting or hashing a counter.

isn't that the definition of stateful?

➕ show 2 replies
loeg • today at 8:34 PM

Where does the counter come from? Couldn't you just use any small-state PRNG (LCG/PCG/Xoroshiro), assuming you don't need truly unpredictable random numbers (given the author mentioned Mersenne Twister)? I know PCG has the seek property the author mentions, although I don't know how cheap it is. Real encryption is a crazy expensive operation compared to anything these PRNGs are doing, although I guess Philox isn't AES.

➕ show 2 replies
leni536 • today at 8:14 PM

Aren't there PRNGs that are designed so that they can be cheaply "forked" into "independent" generators without shared state? (For some value of "indpendent")

➕ show 1 reply
hinkley • today at 7:44 PM

The typical way a CSPRNG is to use cryptography to encrypt something and carving it up into the requested amount of output. This is just a less common variant. Educational perhaps, but newsworthy I don’t know.

➕ show 1 reply