I can give you an algorithm, it's up to you to implement it.
For the first row, you create an collection of numbers from 1 to 8: [1, 2, 3, 4, 5, 6, 7, 8].
Each time, you pick a random number between 1 and the length of the collection. You take the number with that index and you remove it from the collection.
Example:
Collection : [1, 2, 3, 4, 5, 6, 7, 8] (size=8)
Random number : 5
Random number's element : 5
Collection : [1, 2, 3, 4, 6, 7, 8] (size=7)
Random number : 2
Random number's element : 2
Collection : [1, 3, 4, 6, 7, 8] (size=6)
Random number : 5
Random number's element : 7
Collection : [1, 3, 4, 6, 8] (size=5)
...
Like this, you get a first row : [5, 2, 7, ...]
For the second row, you create a new collection:
Collection : [1, 2, 3, 4, 5, 6, 7, 8] (size=8)
First, you remove the "5", as it can't be chosen:
Collection : [1, 2, 3, 4, 6, 7, 8] (size=7)
Random number : 3
Random number's element : 3
Then, you add the "5" and remove the "2", as the "2" can't be chosen in the second column:
Collection : [1, 3, 4, 6, 7, 8, 5] (size=7)
Random number : 3
Random number's element : 4
Then, you add the "2" and remove the "7", as the "7" can't be chosen in the third column:
Collection : [1, 3, 6, 7, 8, 5, 2] (size=6)
...