Get the latest tech news

Efficiently Generating a Number in a Range (2018)


The vast majority of my posts about random number generation have focused on looking at the properties of different generation schemes. But, perhaps surprisingly, the performance of your randomized a

In this post (inspired by and building on an excellent recent paper by Daniel Lemire), we'll explore a common source of overhead in random number generation that frequently outweighs PRNG engine performance. Typically, built-in approaches use one of the other techniques we will describe below, but most users will simply use the facilities provided without thinking too deeply about what is happening behind the scenes, assuming that they are well enough engineered and sufficiently efficient. (Note that 0x1.0p-32 is a binary floating point constant for 2-32 that we use to convert a random integer value in the range [0..2 32) into a double in the unit interval; we could instead perform this conversion using ldexp(rng(), -32) but when I benchmarked this approach, it proved to be much slower option.)

Get the Android app

Or read this on Hacker News

Read more on:

Photo of range

range

Photo of number

number

Related news:

News photo

Design Software Maker Figma, Backers Raise $1.2 Billion in IPO

News photo

A Number Of Problems Make Debian & Other Linux Distros A Pain On Snapdragon X Laptops

News photo

The Number go up rule: Why America refuses to fix anything