A Latin square of size n is an arrangement of n symbols in an n-by-n square in such a way that each row and column has each symbol appearing exactly once.

A randomised Latin square generates random configurations of the symbols for any given n.

Example n=4 randomised Latin square

0 2 3 1
2 1 0 3
3 0 1 2
1 3 2 0
Task

 Create a function/routine/procedure/method/... that given n generates a randomised Latin square of size n.
 Use the function to generate and show here, two randomly generated squares of size 5.
Note
 
Strict Uniformity in the random generation is a hard problem and not a requirement of the task.

Reference

 Wikipedia: Latin square
 OEIS: A002860


sub latin-square { [[0],] };
 
sub random ( @ls, :$size = 5 ) {
 
    # Build
    for 1 ..^ $size -> $i {
        @ls[$i] = @ls[0].clone;
        @ls[$_].splice($_, 0, $i) for 0 .. $i;
    }
 
    # Shuffle
    @ls = @ls[^$size .pick(*)];
    my @cols = ^$size .pick(*);
    @ls[$_] = @ls[$_][@cols] for ^@ls;
 
    # Some random Latin glyphs
    my @symbols = ('A' .. 'Z').pick($size);
 
    @ls.deepmap: { $_ = @symbols[$_] };
 
}
 
sub display ( @array ) { $_.fmt("%2s ").put for |@array, '' }
 
 
# The Task
 
# Default size 5
display random latin-square;
 
# Specified size
display random :size($_), latin-square for 5, 3, 9;
 
# Or, if you'd prefer:
display random latin-square, :size($_) for 12, 2, 1;