The code generate a random permutation of the original array.
However, note that this is biased - it does not generate all permutations in uniform distribution. This thread discusses what is the affect of this bias.
To overcome this issue - you might want to have a look on fisher yates shuffle (which main difference is, to generate a random number in range [i,n) in each iteration instead of in range [0,n).)
EDIT:
You might better understand it if you encapsulate the assignments in a method:
private static void swap(int[] array, int i, int j) {
tempNum = array[j];
array[j] = array[i];
array[i]=tempNum;
}
Now, the code will be simpler to follow:
for(int i = 0; i< leftbut.length; i++) {
//choose a random index in the array
int randomNumber =(int)(Math.random()*leftbut.length);
//swap the element in index i with the random element chosen in the array
swap(leftbut, i, randomNumber);
}
The idea is you swap() each element in the array with a random index. This random index is chosen randomly from the array, and its index is denoted as randomNumber.
Since you only swap() items around, you can easily prove that the output array is a permutation of the original.