public static int[] randomSeam(int n, int range) {
        int[] seam = new int[n];
        seam[0] = StdRandom.uniform(range);
        for (int i = 1; i < n; i++) {
            int index = StdRandom.uniform(-1, 2); // randomly generate -1, 0, 1
            while (seam[i - 1] + index < 0 || seam[i - 1] + index >= range) {
                index = StdRandom.uniform(-1, 2); // randomly generate -1, 0, 1
            }
            seam[i] = seam[i - 1] + index;
        }
        return seam;
    }