We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

Linear congruential generator

From Esolang
Jump to navigation Jump to search

A linear congruential generator is a random number generator that is fast, uses a very small amount of space, and easy to implement. However, the random numbers generated are in a very low quality, not even close to being used as statistical purposes, let alone cryptographical. (See Uhurx for a failed use on that)

The generator has only an integer, x, as an internal state, which often starts as 1. its generation algorithm and transition algorithm are the same, being

output = x(n+1) = (a*x(n)+c) mod m

where a, c, and m are arbitrarily chosen. Some implementations of C implements the rand function as this, with

a=1103515245=0x41c64e6d, c=12345, m=2^32

The generator's period can be only as high as m. With a sufficiently large m, the generator may produce random numbers high enough.

Implementations

C

uint32_t state=1; int rand(){return state=state*1103515245u+12345u;}

><>

This reads a, c, and m as charcodes, in the order, and prints the random numbers infinitely.

1iiv
v@i<
>$:{*}$:{+}@@:{$%:n48*o}@

Shakespeare

linear congruential generator.
Ajax, a.
Cicero, c.
Macbeth, m.
Romeo, stores the current seed.
Solinus, stores a solidus (self explanitory).
Act I:1.
Scene I: initialization.
[Enter Romeo and Ajax]
Romeo: Listen to your heart!
[Exeunt]
[Enter Romeo and Cicero]
Romeo: Listen to your heart!
[Exeunt]
[Enter Romeo and Macbeth]
Romeo: Listen to your heart!
[Exeunt]
[Enter Romeo and Solinus]
Romeo: You are the sum of the sum of a pig and a big big big big big cat and a big big big big cat!
Solinus: You cat!
Scene II:loop.
Solinus: 
You are the product of you and Ajax!
You are the sum of you and Cicero!
You are the remainder of the quotient between you and Macbeth!Open your heart!
Romeo: Speak thy mind!let us return to Scene II.