public int[] generate(int length, int[] seed) {
        //Check to make sure seed is the correct depth
        if (seed.length != this.depth) {
            System.err.println("[WARNING] Wrong seed length for this Matrix depth");
            return null;
        }
        int[] array = new int[length];
        String seedString = "";
        int[] seedbak = new int[seed.length];
        //change seed into a string and add seed to the outgoing array
        for (int i = 0; i < seed.length; i++) {
            array[i] = seed[i];
            seedbak[i] = seed[i];
            seedString += seed[i] + " "; //create the prefix
        }
        String bak = seedString;
        //Check that this seed is available from the matrix
        if (!weightMatrix.containsKey(seedString)) {
            System.err.println("[WARNING] This seed is unavailable .. try another");
            return null;
        }
        //Calculate the new index values
        for (int i = seed.length; i < array.length; i++) {
            if (!weightMatrix.containsKey(seedString)) { //If there are no other choices
                seedString = bak;//select the original seed;
                seed = seedbak;
            }
            double[] tmp = (double[]) weightMatrix.get(seedString);
            seedString = ""; //reset the prefix
            for (int k = 1; k < seed.length; k++) {
                seedString += seed[k] + " ";
                seed[k - 1] = seed[k];
            }
            double rand = Math.random();
            double count = 0.0;
            for (int j = 0; j < tmp.length; j++) {
                count += tmp[j];
                if (count > rand) {
                    array[i] = j;
                    seedString += j + " ";
                    seed[depth - 1] = j;
                    break;
                }
            }
        }
        return array;
    }