lenskit.basic.random.RandomSelector#

class lenskit.basic.random.RandomSelector(config=None, **kwargs)#

Bases: lenskit.pipeline.Component[lenskit.data.ItemList]

Randomly select items from a candidate list.

Stability:
Caller (see Stability Levels).
Parameters:
  • n – The number of items to select, or -1 to randomly permute the items.

  • rng – The random number generator or specification (see Random Seeds). This class supports derivable RNGs.

  • config (RandomConfig | None)

config: RandomConfig#

The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.

__call__(items, query=None, n=None)#
Parameters:
  • items (lenskit.data.ItemList) – The items from which to pick.

  • query (lenskit.data.QueryInput | None) – The recommendation query; optional, and only consulted when the RNG seed is user-dependent.

  • n (int | None) – The number of items to select, overriding the configured value.

Return type:

lenskit.data.ItemList