private float grad(int hashCode, float x, float y, float z) {
        // Convert lower 4 bits of hash code into 12 gradient directions
        int h = hashCode & 15;
        float u = h < 8 ? x : y;
        float v = h < 4 ? y : h == 12 || h == 14 ? x : z;
        return (((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v));
    }