用于程序内容的快速伪随机数生成器 [英] Fast pseudo random number generator for procedural content

查看:145
本文介绍了用于程序内容的快速伪随机数生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个伪随机数生成器,当生成每个数字之前给它一个种子时,它将专门用于快速工作.到目前为止,我看到的大多数生成器都假设您设置一次种子,然后生成一长串数字.到目前为止,看起来与我唯一相似的是Perlin Noise,但它生成的数据太平滑"-对于相似的输入,它往往会产生相似的结果.

I am looking for a pseudo random number generator which would be specialized to work fast when it is given a seed before generating each number. Most generators I have seen so far assume you set seed once and then generate a long sequence of numbers. The only thing which looks somewhat similar to I have seen so far is Perlin Noise, but it generates too "smooth" data - for similar inputs it tends to produce similar results.

生成器的声明应类似于:

The declaration of the generator should look something like:

int RandomNumber1(int seed);

或者:

int RandomNumber3(int seedX, int seedY, int seedZ);

我认为拥有良好的RandomNumber1就足够了,因为可以通过散列其输入并将结果传递给RandomNumber1来实现RandomNumber3,但是我写了第二个原型,以防某些实现可以使用独立的输入.

I think having good RandomNumber1 should be enough, as it is possible to implement RandomNumber3 by hashing its inputs and passing the result into the RandomNumber1, but I wrote the 2nd prototype in case some implementation could use the independent inputs.

此生成器的预期用途是将其用于过程内容生成器,例如通过将树放置在网格中并确定每个位置的随机树种和随机空间偏移来生成森林.

The intended use for this generator is to use it for procedural content generator, like generating a forest by placing trees in a grid and determining a random tree species and random spatial offsets for each location.

生成器必须非常高效(低于500个CPU周期),因为在渲染过程中会实时大量创建程序内容.

The generator needs to be very efficient (below 500 CPU cycles), because the procedural content is created in huge quantities in real time during rendering.

推荐答案

似乎您在要求哈希函数而不是PRNG.谷歌搜索快速哈希函数"会产生一些有希望的结果.

Seems like you're asking for a hash-function rather than a PRNG. Googling 'fast hash function' yields several promising-looking results.

例如:

uint32_t hash( uint32_t a)
    a = (a ^ 61) ^ (a >> 16);
    a = a + (a << 3);
    a = a ^ (a >> 4);
    a = a * 0x27d4eb2d;
    a = a ^ (a >> 15);
    return a;
}

是的,某些哈希函数肯定比其他哈希函数更合适.

Yep, some hash functions definitely look more suitable than others.

为您的目的,充分了解该功能并检查输入中的单个位更改是否会传播到很多输出位,就足够了.

For your purposes, it should be sufficient to eyeball thefunction and check that a single-bit change in the input will propagate to lots of output bits.

这篇关于用于程序内容的快速伪随机数生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆