为什么我使用 Numba 得到与随机数组相同的数字xoroshiro128p?我想要与 Numpy 随机数组相同np.random.rand。
from numba import cuda
from numba.cuda.random import create_xoroshiro128p_states, xoroshiro128p_uniform_float32
import numpy as np
@cuda.jit
def rand_array(rng_states, out):
thread_id = cuda.grid(1)
x = xoroshiro128p_uniform_float32(rng_states, thread_id)
out[thread_id] = x
threads_per_block = 4
blocks = 3
rng_states = create_xoroshiro128p_states(threads_per_block * blocks, seed=1)
out = np.zeros(threads_per_block * blocks, dtype=np.float32)
rand_array[blocks, threads_per_block](rng_states, out)
rar = np.random.rand(12).reshape(blocks, threads_per_block)
print(out.reshape(blocks,threads_per_block))
print()
print(rar.reshape(blocks,threads_per_block))
每次运行它时,我都会看到相同的数字。但np.random.rand效果很好。预先感谢您的帮助!
慕容708150
相关分类