ArticleslgStudy

mathematics

Counter-based random number generator

Counter-based random number generator is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Counter-based random number generator rather than just read about it. In short: A counter-based random number generation (CBRNG, also known as a counter-based pseudo-random number generator, or CBPRNG) is a kind of pseudorandom number generator that uses only an integer counter as its internal state. They are generally used for generating pseudorandom numbers for large parallel computations.

Key takeaways

  • Counter-based random number generator belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Counter-based random number generator to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Counter-based random number generator from memory before moving on to harder problems.

Reference excerpt

A counter-based random number generation (CBRNG, also known as a counter-based pseudo-random number generator, or CBPRNG) is a kind of pseudorandom number generator that uses only an integer counter as its internal state. They are generally used for generating pseudorandom numbers for large parallel computations.

Background We can think of a pseudorandom number generator (PRNG) as a function that transforms a series of bits known as the state into a new state and a random number. That is, given a PRNG function and an initial state state0, we can repeatedly use the PRNG to generate a sequence of states and random numbers. PRNG(state0)=state1, num1PRNG(state1)=state2, num2PRNG(state2)=state3, num3PRNG(state3)=… In some PRNGs, such as the Mersenne Twister, the state is large, more than 2048 bytes. In other PRNGs, such as xorshift, statei and numi are one and the same (and so the state is small, just 4, 8, or 16 bytes, depending on the size of the numbers being generated). But in both cases, and indeed in most traditional PRNGs, the state evolves unpredictably, so if you want to calculate a particular statei given an initial state state0, you have to calculate state1, state2, and so on, running the PRNG i times. Such algorithms are inherently sequential and not amenable to running on parallel machines like multi-core CPUs and GPUs. In contrast, a counter-based random number generator (CBRNG) is a PRNG where the state "evolves" in a particularly simple manner: statei=i. This way you can generate each number independently, without knowing the result of the previous call to the PRNG. This property make it easy to run a CBRNG on a multiple CPU threads or a GPU. For example, to generate n random numbers on a GPU, you might spawn n threads and have the ith thread calculate PRNG(i).

CBRNGs based on block ciphers Some CBRNGs are based on reduced-strength versions of block ciphers. Below we explain how this works. When using a cryptographic block cipher in counter mode, you generate a series of blocks of random bits. The ith block is calculated by encrypting the number i using the encryption key k: Blocki=E(i,k). This is similar to a CBRNG, where you calculate the ith random number as PRNG(i). Indeed, any block cipher can be used as a CBRNG; simply let PRNG(i)=E(i,seed)! This yields a strong, cryptographically-secure source of randomness. But cryptographically secure pseudorandom number generators tend to be slow compared to insecure PRNGs, and in practice many uses of random numbers don't require this degree of security. In 2011, Salmon et al. at D. E. Shaw Research introduced two CBRNGs based on reduced-strength versions of block ciphers.

Threefry uses a reduced-strength version of the Threefish block cipher. (Juvenile fish are known as "fry".) ARS uses a reduced-strength version of the AES block cipher. ("ARS" is a pun on "AES"; "AES" stands for "advanced encryption standard", and "ARS" stands for "advanced randomization system"). ARS is used in recent versions of Intel's Math Kernel Library and gets good performance by using instructions from the AES-NI instruction set, which specifically accelerate AES encryption. Code implementing Threefry, ARS, and Philox (see below) is available from the authors.

CBRNGs based on multiplication In addition to Threefry and ARS, Salmon et al. described a third counter-based PRNG, Philox, based on wide multiplies; e.g. multiplying two 32-bit numbers and producing a 64-bit number, or multiplying two 64-bit numbers and producing a 128-bit number. As of 2020, Philox is popular on CPUs and GPUs. On GPUs, nVidia's cuRAND library and TensorFlow provide implementations of Philox. On CPUs, Intel's MKL provides an implementation. A more recent CBRNG based on multiplication is the Squares RNG, which applies four rounds of squaring to a counter for a 32-bit output, or five rounds for a 64-bit output. Its author reports that both versions pass stringent tests of randomness and that they "may be the fastest counter-based generators". L'Ecuyer et al. confirm that the proposal passes the standard empirical tests of L'Ecuyer and Simard, but note that it fails with only three rounds and describe the construction as highly heuristic. Unlike a block cipher, it is not known to produce every 32-bit output equally often as the counter runs over its full range, and output quality depends strongly on the key: for the key 0 the output is always 0, and for a small integer key k approximately the first 216/k outputs are 0. Consequently, using 1, 2, ..., s as keys to define s streams — a common practice — gives poor results unless the keys are first hashed to random-looking values.

References

Worked examples

Example 1 — a first encounter with Counter-based random number generator

Start with the simplest possible case. Write down what Counter-based random number generator claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Counter-based random number generator before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Counter-based random number generator ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Counter-based random number generator

In research
Counter-based random number generator appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Counter-based random number generator in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Counter-based random number generator is common in secondary-school and first-year university syllabi. It links to neighbouring topics Pseudorandom number generators, so understanding it makes those chapters shorter.
In everyday life
Look for Counter-based random number generator outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Counter-based random number generator” →

How to study Counter-based random number generator in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Counter-based random number generator means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Counter-based random number generator out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Counter-based random number generator in simple terms?

A counter-based random number generation (CBRNG, also known as a counter-based pseudo-random number generator, or CBPRNG) is a kind of pseudorandom number generator that uses only an integer counter as its internal state. They are generally used for generating pseudorandom numbers for large paralle…

Why does Counter-based random number generator matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Counter-based random number generator?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Counter-based random number generator.

Tags

  • Pseudorandom number generators

Keep exploring