lenskit.util.random#

Utilities to manage randomness in LensKit and LensKit experiments.

Functions

derivable_rng(spec)

Get a derivable RNG, for use cases where the code needs to be able to reproducibly derive sub-RNGs for different keys, such as user IDs.

Classes

DerivingRNG(seed)

RNG provider that derives new RNGs from the key

FixedRNG(rng)

RNG provider that always provides the same RNG

class lenskit.util.random.FixedRNG(rng)#

Bases: object

RNG provider that always provides the same RNG

class lenskit.util.random.DerivingRNG(seed)#

Bases: object

RNG provider that derives new RNGs from the key

lenskit.util.random.derivable_rng(spec)#

Get a derivable RNG, for use cases where the code needs to be able to reproducibly derive sub-RNGs for different keys, such as user IDs.

Parameters:

spec

Any value supported by the seed parameter of seedbank.numpy_rng(), in addition to the following values:

  • the string 'user'

  • a tuple of the form (seed, 'user')

Either of these forms will cause the returned function to re-derive new RNGs.

Returns:

A function taking one (or more) key values, like derive_seed(), and returning a random number generator.

Return type:

function