I got a working perlin noise 1D code and it always outputs the same result. I want to add a seed to it, that it only gives the same when using the same seed, but I don't know where I should put it.
Here's the class with the Perlin noise:
public class ClassNoise { public static List<Integer[]> primes = new ArrayList<Integer[]>(); static { int prime1 = 0; int prime2 = 0; int prime3 = 0; for (int i = 1; i < 10000000; i+=2) { if (isPrime(i)) { prime1 = i; for (; i < 10000000; i+=2) { if (isPrime(i)) { //primes.add(i); prime2 = i; for (; i < 10000000; i+=2) { if (isPrime(i)) { prime3 = i; primes.add(new Integer[]{prime1,prime2,prime3}); } } } } } } } public static float Noise(int x, int octave) { x = (x << 13) ^ x; return (float) (1.0 - ((x * (x * x * primes.get(octave)[0] + primes.get(octave)[1]) + primes.get(octave)[2]) & Integer.MAX_VALUE) / 1073741824f); } public static float PerlinNoise1D(float x, float persistence, int octaves) { float total = 0; float p = persistence; int n = octaves - 1; float[] octavePostMutliply = { 1, 1, 1, 1, 1, 1, 1, 1 }; for (int i = 0; i <= n; i++) { float frequency = (float) Math.pow(2, i); double amplitude = Math.pow(p, octaves - i); total += InterpolatedNoise(x * frequency, i) * amplitude * octavePostMutliply[i]; } return total; } private static float InterpolatedNoise(float x, int octave) { int integer_X = (int) x; float fractional_X = x - integer_X; float v1 = SmoothNoise1D(integer_X, octave); float v2 = SmoothNoise1D(integer_X + 1, octave); return CosineInterpolate(v1, v2, fractional_X); } public static float CosineInterpolate(float a, float b, float x) { float ft = (float) (x * Math.PI); float f = (float) ((1 - Math.cos(ft)) * 0.5); return a * (1 - f) + b * f; } public static float SmoothNoise1D(int x, int octave) { return Noise(x, octave) / 2 + Noise(x - 1, octave) / 4 + Noise(x + 1, octave) / 4; } private static boolean isPrime(int n) { if (n % 2 == 0) return false; for (int i = 3; i * i <= n; i += 2) { if (n % i == 0) return false; } return true; } }