uniform#

nvmath.device.random.uniform(state)#

使用指定的位生成器状态从均匀分布中采样一个浮点数。

参数:

state – 对应于位生成器之一的状态对象。

返回值:

类型为 float32 的值。

示例

以下内核的 states 参数应为已初始化的位生成器状态数组。有关如何创建和初始化位生成器状态的更多详细信息,请参阅 nvmath.device.random.init() 的文档。

>>> from numba import cuda
>>> from nvmath.device import random
>>> compiled_apis = random.Compile()
>>> @cuda.jit(link=compiled_apis.files, extensions=compiled_apis.extension)
... def kernel(states):
...     i = cuda.grid(1)
...     value = random.uniform(states[i])