Random number for GPU

本文探讨了使用CUDA进行高效伪随机数生成的方法和技术,包括cuRAND库、快速GPU随机数生成、高质量伪随机数生成器以及GPU伪随机数生成库GPUTEA。此外,介绍了基于“TEA”加密算法的伪随机数生成函数,并提供了Morton编码和无符号整数位反转等技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Efficient random number generation and application using CUDA

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch37.html


cuRAND: Nvidia random number generation library

https://developer.nvidia.com/cuRAND


Quick and easy gpu random numbers in D3D11:

http://www.reedbeta.com/blog/2013/01/12/quick-and-easy-gpu-random-numbers-in-d3d11/


A Fast high quality pseudo random number generator for nVidia CUDA

http://www0.cs.ucl.ac.uk/staff/ucacbbl/ftp/papers/langdon_2009_CIGPU.pdf


GPU pseudo random number: GPU TEA

http://www.csee.umbc.edu/~olano/papers/GPUTEA.pdf


/*
* Pseudo random number generator, based on "TEA, a tiny Encrytion Algorithm"
* http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.45.281&rep=rep1&type=pdf
* @param v - old seed (full 32bit range)
* @param IterationCount - >=1, bigger numbers cost more performance but improve quality
* @return new seed
*/
uint2 ScrambleTEA(uint2 v, uint IterationCount = 3)
{
    // Start with some random data (numbers can be arbitrary but those have been used by others and seem to work well)
    uint k[4] = { 0xA341316Cu, 0xC8013EA4u, 0xAD90777Du, 0x7E95761Eu };


    uint y = v[0];
    uint z = v[1];
    uint sum = 0;


    for (uint i = 0; i < IterationCount; ++i)
    {
        sum += 0x9e3779b9;
        y += (z << 4u) + k[0] ^ z + sum ^ (z >> 5u) + k[1];
        z += (y << 4u) + k[2] ^ y + sum ^ (y >> 5u) + k[3];
    }


    return uint2(y, z);
}



uint MortonCode(uint x)
{
    x = (x ^ (x << 2)) & 0x33333333;
    x = (x ^ (x << 1)) & 0x55555555;
    return x;
}




uint ReverseUIntBits(uint bits)
{
    bits = ((bits & 0x33333333) << 2) | ((bits & 0xcccccccc) >> 2);
    bits = ((bits & 0x55555555) << 1) | ((bits & 0xaaaaaaaa) >> 1);
    return bits;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值