Class WhiteNoise

java.lang.Object
squidpony.squidmath.WhiteNoise
All Implemented Interfaces:
Noise.Noise1D, Noise.Noise2D, Noise.Noise3D, Noise.Noise4D, Noise.Noise6D

public class WhiteNoise
extends Object
implements Noise.Noise1D, Noise.Noise2D, Noise.Noise3D, Noise.Noise4D, Noise.Noise6D
Performance-oriented white noise generator for 1D, 2D, 3D, 4D, and 6D. Produces noise values from -1.0 inclusive to 1.0 exclusive. Should produce a completely different double even for extremely-nearby points, so this is not a kind of continuous noise like SeededNoise. It is not actually random, and the value is always determined by the exact double positions (and possibly a long seed) given to it. Even a slight change should drastically alter the returned value, though below some very small epsilon the results might not be different between two very close points in space. The output should look like "TV static" if rendered as grayscale pixels.
Meant for cases where you want to use a different number for every pixel, tile, or other unit of noise generated, often coupled with another kind of noise but with the result of the WhiteNoise made less significant to add a "fuzzy" effect to the appearance.
Implementation is based on CrossHash.Wisp.hash64(double[]), treating doubles as ints by using NumberTools.doubleToMixedIntBits(double), which XORs the bottom and top halves of the long bits of each double. Finishes by passing the top 52 bits as a significand to NumberTools.longBitsToDouble(long), using an exponent that allows this to produce numbers between -1.0 and 1.0. Has special treatment for the seed when present (since it is a long).
This can also be used as a sort of hashing function that produces a double, if you find a need for such a thing, with hash(double...).
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static WhiteNoise instance  
  • Constructor Summary

    Constructors 
    Constructor Description
    WhiteNoise()  
  • Method Summary

    Modifier and Type Method Description
    double getNoise​(double x)  
    double getNoise​(double x, double y)  
    double getNoise​(double x, double y, double z)  
    double getNoise​(double x, double y, double z, double w)  
    double getNoise​(double x, double y, double z, double w, double u, double v)  
    double getNoiseWithSeed​(double x, double y, double z, double w, double u, double v, long seed)  
    double getNoiseWithSeed​(double x, double y, double z, double w, long seed)  
    double getNoiseWithSeed​(double x, double y, double z, long seed)  
    double getNoiseWithSeed​(double x, double y, long seed)  
    double getNoiseWithSeed​(double x, long seed)  
    static double hash​(double... data)
    Hashes the input double array or vararg and produces a double with unpredictable value, between -1.0 inclusive and 1.0 exclusive.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait