int[] randperm(int upto) {
        int perm[] = new int[upto];
        int freenums[] = new int[upto];

        for (int i = 0; i < upto; i++) {
            freenums[i] = i + 1;
        }
        for (int i = 1; i <= upto; i++) {
            int num = (int) Math.floor(random() * (upto + 1 - i) + 1.0);
            perm[i - 1] = freenums[num - 1];
            freenums[num - 1] = freenums[upto - i];
        }
        return perm;
    }