public static void setDistance(Red r1, Red r2, int d) {
        int N = r1.getSize();
        int M = N;
        int s1, s2, i, n;
        int[] st = new int[N];
        int[] rst = new int[d];

        for (n = 0; n < N; ++n) {
            st[n] = n;
            s1 = r1.getNodo(n).getS();
            r2.getNodo(n).setS(s1);
        }

        --M;
        for (n = 0; n < d; ++n) {
            i = (int) (M * Math.random());
            rst[n] = st[i];
            st[i] = st[M - 1];
            --M;
        }

        for (n = 0; n < d; ++n) {
            i = rst[n];
            s1 = r1.getNodo(i).getS();
            if (r1.getNodo(i).isBinary()) {
                s2 = 1 - s1;
            } else {
                if (s1 == 0) {
                    s2 = (Math.random() < 0.5) ? 1 : 2;
                } else {
                    if (s1 == 1) {
                        s2 = (Math.random() < 0.5) ? 0 : 2;
                    } else {
                        s2 = (Math.random() < 0.5) ? 0 : 1;
                    }
                }
            }
            r2.getNodo(i).setS(s2);
        }

    }