KissSeedSequence#

class scikitplot.random.KissSeedSequence(entropy=None, *, spawn_key=(), pool_size=4, n_children_spawned=0)[source]#

Seed sequence compatible with numpy.random.SeedSequence.

Parameters:
entropy{None, int, sequence of int}, optional

Entropy source. If None, uses OS randomness.

spawn_keytuple of int, default=()

Spawn key for child sequences

pool_sizeint, default=4

Pool size (for NumPy compatibility, not used)

n_children_spawnedint, default=0

Number of children spawned

Attributes:
entropyint or None

Initial entropy value

spawn_keytuple of int

Spawn key tuple

pool_sizeint

Pool size

n_children_spawnedint

Count of spawned children

Raises:
ValueError

If pool_size < 1 or n_children_spawned < 0

TypeError

If entropy has invalid type

Parameters:
  • entropy (int | Sequence[int] | None)

  • spawn_key (Sequence[int])

  • pool_size (int)

  • n_children_spawned (int)

See also

Kiss32Random

32-bit version for smaller datasets

Kiss64Random

64-bit version for larger datasets

KissRandom

Factory function for auto-detecting

KissBitGenerator

NumPy-compatible bit generator

KissGenerator

High-level generator using this BitGenerator

KissRandomState

Inherites from KissGenerator

default_rng

Convenience function to create generator

numpy.random.SeedSequence

NumPy’s seed sequence implementation

Notes

Simplified implementation of NumPy SeedSequence protocol. Compatible but uses simpler mixing algorithm.

References

[1]

O’Neill, M.E. (2015). “PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation.” https://www.pcg-random.org/

[2]

NumPy Enhancement Proposal 19: Random Number Generator Policy https://numpy.org/neps/nep-0019-rng-policy.html

Examples

>>> seq = KissSeedSequence(42)
>>> state = seq.generate_state(4, dtype=np.uint32)
>>> children = seq.spawn(2)
>>>
>>> # Serialization
>>> import pickle
>>> restored = pickle.loads(pickle.dumps(seq))
classmethod deserialize(cls, dict data: dict)#

Deserialize from dictionary.

Parameters:
datadict

Serialized state from serialize()

Returns:
KissSeedSequence

Restored instance

Parameters:

data (dict)

Examples

>>> import json
>>> seq = KissSeedSequence(42)
>>> json_str = json.dumps(seq.serialize())
>>> data = json.loads(json_str)
>>> restored = KissSeedSequence.deserialize(data)
classmethod from_dict(cls, dict data: dict)#

Alias for deserialize().

Parameters:

data (dict)

generate_state(self, int n_words: int, dtype: DTypeLike = np.uint32) NDArray[np.uint32 | np.uint64]#

Generate state array for RNG initialization.

Parameters:
n_wordsint

Number of words to generate

dtypedtype-like, default=np.uint32

Output data type (uint32 or uint64)

Returns:
ndarray

State array of requested dtype

Raises:
ValueError

If n_words < 1 If dtype is not uint32 or uint64

Parameters:
Return type:

ndarray[tuple[Any, …], dtype[uint32 | uint64]]

Notes

Generates deterministic state from entropy and spawn_key. Uses multiplicative congruential generator for mixing.

Examples

>>> seq = KissSeedSequence(42)
>>> state = seq.generate_state(4, dtype=np.uint32)
>>> print(state.shape)
(4,)
get_params(self, bool deep: bool = True) dict#

Get parameters (sklearn-style).

Parameters:
deepbool, default=True

If True, return params for nested objects

Returns:
dict

Parameter dictionary

Parameters:

deep (bool)

Return type:

dict

Examples

>>> seq = KissSeedSequence(42)
>>> params = seq.get_params()
>>> print(params["entropy"])
42
get_state(self) dict#

Get current state as dictionary.

Returns:
dict

Complete state dictionary

Return type:

dict

Examples

>>> seq = KissSeedSequence(42)
>>> state = seq.get_state()
>>> print(state["entropy"])
42
serialize(self) dict#

Serialize to JSON-compatible dict.

Returns:
dict

JSON-serializable state

Return type:

dict

Examples

>>> import json
>>> seq = KissSeedSequence(42)
>>> data = seq.serialize()
>>> json_str = json.dumps(data)
set_params(self, **params)#

Set parameters (sklearn-style).

Parameters:
**paramsdict

Parameters to set

Returns:
self

For method chaining

Examples

>>> seq = KissSeedSequence(42)
>>> seq.set_params(entropy=123)
>>> print(seq.entropy)
123
set_state(self, dict state: dict) None#

Set state from dictionary.

Parameters:
statedict

State from get_state()

Raises:
ValueError

If state is invalid

Parameters:

state (dict)

Return type:

None

Examples

>>> seq1 = KissSeedSequence(42)
>>> state = seq1.get_state()
>>> seq2 = KissSeedSequence(0)
>>> seq2.set_state(state)
>>> print(seq2.entropy == seq1.entropy)
True
spawn(self, int n_children: int) list#

Create independent child seed sequences.

Parameters:
n_childrenint

Number of children to spawn

Returns:
list of KissSeedSequence

Independent child sequences

Raises:
ValueError

If n_children < 1

Parameters:

n_children (int)

Return type:

list

Notes

Each child has a unique spawn_key derived from the parent’s spawn_key and its position in the child list. This ensures statistical independence even with identical entropy.

The spawn tree structure allows for hierarchical parallelization: master → workers → tasks, where each level is independent.

Examples

>>> seq = KissSeedSequence(42)
>>> children = seq.spawn(3)
>>> print(len(children))
3
KissSeedSequence.state -> dict[str, Any]

Get current state as dictionary.

Returns:
dict

State dictionary with keys: - ‘entropy’: int or None - ‘spawn_key’: tuple of int - ‘pool_size’: int - ‘n_children_spawned’: int

Notes

State can be used for serialization and restoration.

Examples

>>> seq = KissSeedSequence(42)
>>> state = seq.state
>>> # Restore with: KissSeedSequence(**state)
to_dict(self) dict#

Alias for serialize().

Return type:

dict