Xoshiro128pp#
- class vulkpy.random.Xoshiro128pp#
Bases:
PRNG
xoshiro128++: Pseudo Random Number Generator
Notes
This class implements xoshiro128++ [1]. Initial internal states are sequentially generated during construction on CPU and are spaced 2^64 steps. Generating (pseudo-)random numbers are executed parallelly on GPU.
References
Methods Summary
normal
(*[, shape, buffer, mean, stddev])Generate Normal Distributing numbers
randint
(*[, shape, buffer])Generate [0, 2^32) unsigned integer numbers
random
(*[, shape, buffer])Generate [0, 1) floating numbers
randrange
(*[, shape, buffer, low, high])Generate [low, high) random numbers
wait
()Methods Documentation
- normal(*, shape: Iterable[int] | None = None, buffer: Array | None = None, mean: float = 0.0, stddev: float = 1.0) Array #
Generate Normal Distributing numbers
- Parameters:
shape (iterable of ints, optional) – If specified, new
vulkpy.Array
withshape
will be returned.buffer (vulkpy.Array) – If specified, generated numbers will be stored.
- Returns:
Array which will get random numbers.
- Return type:
- Raises:
ValueError – If neither
shape
orbuffer
are specified
Notes
This method first generates [0, 1) uniform random numbers, then transforms them to normal distribution with Box-Muller method. Box-Muller might have problem in terms of random number quality, however, it is quite GPU friendly.
- randint(*, shape: Iterable[int] | None = None, buffer: U32Array | None = None) U32Array #
Generate [0, 2^32) unsigned integer numbers
- Parameters:
shape (iterable of ints, optional) – If specified, new
vulkpy.U32Array
withshape
will be returned.buffer (vulkpy.U32Array) – If specified, generated numbers will be stored.
- Returns:
Array which will get random numbers.
- Return type:
- Raises:
ValueError – If neither
shape
orbuffer
are specified.
- random(*, shape: Iterable[int] | None = None, buffer: Array | None = None) Array #
Generate [0, 1) floating numbers
- Parameters:
shape (iterable of ints, optional) – If specified, new
vulkpy.Array
withshape
will be returned.buffer (vulkpy.Array) – If specified, generated numbers will be stored.
- Returns:
Array which will get random numbers.
- Return type:
- Raises:
ValueError – If neither
shape
orbuffer
are specified.
- randrange(*, shape: Iterable[int] | None = None, buffer: U32Array | None = None, low: int = 0, high: int = 4294967296) U32Array #
Generate [low, high) random numbers
- Parameters:
shape (iterable of ints, optional) – If specified, new
vulkpy.U32Array
withshape
will be returned.buffer (vulkpy.Array) – If specified, generated numbers will be stored.
low (int, optional) – Inclusive lowest value. The default is
0
.high (int, optional) – Exclusive highest value. The default is
2^32
.
- Returns:
Array which will get random numbers.
- Return type:
- Raises:
ValueError – If neither
shape
orbuffer
are specified.ValueError – If not 0 <= low < high <= 2^32.
- wait()#
- __init__(gpu: GPU, size: int = 64, *, seed: int | None = None)#
Initialize Xoshiro128pp
- Parameters:
gpu (vulkpy.GPU) – GPU where PRNG allocates
size (int) – Number of internal states. These states generate random number parallelly.
seed (int, optional) – Random seed. If
None
(default), use hardware random instead.