~/bend-docscommunity

math_random.bend checks

raw source on the hub · import stelliferous@0.0.4.0/math_random.bend as Math_random

Random numbers by counter: the word of an element depends only on the seed, the stream and its index, so results do not depend on the worker count. Each word is the first output of Threefry-2x32 with 20 rounds (Salmon et al. 2011) for the key (seed, stream) and the counter (index, 0).

2 imports
import Base
import ./math_fp32.bend as Fp32

Types

type Key source · line 8 · raw

Data

type Block source · line 12 · raw

Data

Two words of the cipher state.

type Bounded source · line 78 · raw

Data

Definitions

def rotated source · line 15 · raw

@+word:U32 -> @+left:Nat -> @+right:Nat -> U32

def round source · line 18 · raw

@block:Block -> @+left:Nat -> @+right:Nat -> Block

def keyed source · line 23 · raw

@block:Block -> @+first:U32 -> @+second:U32 -> Block

def even_rounds source · line 28 · raw

@block:Block -> Block

The four rounds of the even and of the odd schedule.

def odd_rounds source · line 31 · raw

@block:Block -> Block

def enciphered source · line 35 · raw

@+first:U32 -> @+second:U32 -> @+third:U32 -> @+counter:U32 -> @+high:U32 -> Block

The first word of the cipher of the counter under the key words.

def block source · line 39 · raw

@+seed:U32 -> @+stream:U32 -> @+index:U32 -> @+high:U32 -> Block

def first source · line 42 · raw

@block:Block -> U32

def word source · line 46 · raw

@+key:Key -> @+index:U32 -> U32

def uniform source · line 51 · raw

@+key:Key -> @+index:U32 -> F32

The top 24 bits of the word scaled to [0, 1), exactly.

def high_product source · line 55 · raw

@+left:U32 -> @+right:U32 -> U32

The top 32 bits of the 64-bit product of two words.

def below source · line 67 · raw

@+bound:U32 -> @+key:Key -> @+index:U32 -> F32

An integer below the bound, by the top of the product of the word and the bound, as an FP32.

def counter source · line 71 · raw

@index:U32 -> @value:F32 -> F32

The counter is carried in the element's bits, which are only moved.

def uniform_of_counter source · line 74 · raw

@key:Key -> @value:F32 -> F32

def below_of_counter source · line 81 · raw

@bounded:Bounded -> @value:F32 -> F32