问题描述
我整天都在为此苦苦挣扎,我试图在我的 CUDA 代码中为线程获取一个随机数生成器.我浏览了所有论坛,是的,这个话题出现了很多,但我花了几个小时试图解开各种代码,但无济于事.如果有人知道一个简单的方法,可能是一个 device 内核,可以调用它来返回 0 到 1 之间的随机浮点数,或者我可以转换的整数,我将不胜感激.
I've struggled with this all day, I am trying to get a random number generator for threads in my CUDA code. I have looked through all forums and yes this topic comes up a fair bit but I've spent hours trying to unravel all sorts of codes to no avail. If anyone knows of a simple method, probably a device kernel that can be called to returns a random float between 0 and 1, or an integer that I can transform I would be most grateful.
再次,我希望在内核中使用随机数,就像 rand() 一样.
Again, I hope to use the random number in the kernel, just like rand() for instance.
提前致谢
推荐答案
我不确定我理解你为什么需要一些特别的东西.任何传统的 PRNG 都应该或多或少地直接移植.线性同余 应该可以正常工作.您是否有一些正在尝试建立的特殊属性?
I'm not sure I understand why you need anything special. Any traditional PRNG should port more or less directly. A linear congruential should work fine. Do you have some special properties you're trying to establish?
这篇关于CUDA 中的随机数生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!