Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
// create a hashing array
int n = array.length;
int[] x = new int[n];
Random rand = new Random();
for (int i=0; i<n; i++)
x[i] = i;
// changing k change the mapping
int k = rand.nextInt(n/2);
int s;
for (int i=0; i<3; i++) {
for (int j=0; j<n; j++) {
s = x[i];
k = (k+s) % n;
x[i] = x[k];
x[k] = s;
}
}
}
// now use the hashing array to get item from the array in shuffled order
for (int i=0; i<n; i++) {
array[x[i]];
}
chance that the hash is not perfect
n (not one to one mapping)
--- -------------------------------
2 .25
3 .2213773
4 .0941787
5 .0091061
6 .0000137
7 .0000000000000003