噪声的伪随机数发生器 [英] Pseudorandom number generator for noise
问题描述
我正在尝试制作 http://freespace.virgin.net/hugo.elias/models/m_perlin.htm 使用 Lua.但是,它不能正常工作,因为 Lua 不支持按位运算符,这是该页面上的伪随机数函数所必需的.我试着用 randomseed() 搞乱,但我能想出的一切都只是制作了非常奇怪的模式.我需要一个伪随机数生成器,当给定参数 x、y 和随机种子时,它将生成 -1 和 1 之间的数字.伪代码没问题.
I'm trying to make the Perlin noise algorithm described at http://freespace.virgin.net/hugo.elias/models/m_perlin.htm using Lua. However, it doesn't work properly since Lua doesn't support bitwise operators, which are necessary for the pseudorandom number function on that page. I tried messing around with randomseed() but everything I could come up with just made really bizarre patterns. I need a pseudorandom number generator that will generate numbers between -1 and 1 when given the parameters x, y, and a random seed. Pseudocode is fine.
谢谢!
推荐答案
已经有 lua 库为此而设计,我发现的一个是:lrandom
There have been lua libraries made for this, one I found is: lrandom
它使用可能更适合您需求的 Mersenne Twister 算法.
It uses the Mersenne Twister algorithm which may suit your needs better.
这篇关于噪声的伪随机数发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!