Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a noise function without binary operators?

Tags:

random

lua

noise

Is there any possible way to make pseudorandom numbers without any binary operators? Being that this is a 3D map, I'm trying to make it as a function of X and Y but hopefully include a randomseed somewhere in their so it won't be the same every time. I know you can make a noise function like this with binary operators :

double PerlinNoise::Noise(int x, int y) const
{
    int n = x + y * 57;
    n = (n << 13) ^ n;
    int t = (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff;
    return 1.0 - double(t) * 0.931322574615478515625e-9;/// 1073741824.0);
}

But being that I'm using lua instead of C++, I can't use any binary operators. I've tried many different things yet none of them work. Help?

like image 306
SDuke Avatar asked Apr 24 '26 13:04

SDuke


2 Answers

For bit operators (I guess that is what you mean by "binary"), have a look at Bitwise Operators Wiki page, which contains a list of modules you can use, like Lua BitOp and bitlib.

If you do not want to implement it by yourself, have a look at the module lua-noise, which contains an implementation of Perlin noise. Note that it is a work-in-progress C module.

like image 157
Michal Kottman Avatar answered Apr 27 '26 21:04

Michal Kottman


If I'm not mistaken, Matt Zucker's FAQ on Perlin noise only uses arithmetic operators to describe/implement it. It only mentions bitwise operators as an optimization trick.

You should implement both ways and test them with the same language/runtime, to get an idea of the speed difference.

like image 29
Nowhere man Avatar answered Apr 27 '26 22:04

Nowhere man



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!