Reputation: 471
I am developing a Perlin Noise generator which works based on a seed integer and on two other integers: x and y.
By now, the pseudo-random number generator is looking like this:
private float noise(int x, int y) {
int n = x + y * seed;
return (1.0f - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824f);
}
But there are some problems with this implementation: first of all, the return interval is not constant (ideally, I would like to work with [-1, 1] or [0, 1]) and for negative x and y values, the pattern gets blocky, not looking organic at all. Is there a way to change my formula (or maybe a totally new one) which would make it fit my needs?
Upvotes: 1
Views: 626
Reputation: 15641
I use this one (i found it on the net, but i don't have the original link anymore):
private double noise(int x, int y) {
int n=(int)x*331+(int)y*337; // add your seed on this line.
n=(n<<13)^n;
int nn=(n*(n*n*41333 +53307781)+1376312589)&0x7fffffff;
return ((1.0-((double)nn/1073741824.0))+1)/2.0;
}
You can easy add your seed to it.
Upvotes: 1