Square-Random-Symmetrical Challenge

Write a program or a function that returns or prints a square-random-symmetrical matrix.



Input

N: The size of the matrix i.e 6 x 6



Output

The matrix. You can either print it, return it as string (with the newlines) or as a list/array of lists/arrays.



Rules


You need to use at least N different characters, where N is the size of the square matrix (input). Since we 're using only letter [a, z][A, Z] and digits [0, 9] (and only 1 digit at the time) you can assume that N &lt; 27 and N &gt; 2, that is because at N &lt;= 2 you can't have both letters and digits. Last but not least, every letter/digit must have non-zero probability of occurring (uniform distribution is not a necessity). However, the result must have at least N different letter/digits.
The matrix has to be both horizontally and vertically symmetrical.
Exactly 2 rows and 2 columns must contain strictly one single-digit number (it's position should be random as well). The rest of rows/cols will contain only letters. Consider letters as [a, z] and [A, Z] and of course single-digit numbers as [0, 9].
Just to be easier, you can assume that the case of the letters doesn't matter, as long as the cases are symmetrical which means: a=A, b=B, etc.
Every possible output must have a non-zero probability of occurring. The random distribution doesn't need to be uniform.




Example

Input: 8

Output:

c r p s s p r c
r k o z z o k r
u t 2 a a 2 t u
y n q z z q n y
y n q z z q n y
u t 2 a a 2 t u
r k o z z o k r
c r p s s p r c
R, 124 118 bytes



function(n,i=(n+1)/2,j=n%/%2,m="[&lt;-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y&lt;-rbind(m,m[j:1,]),y[,j:1])
`-`=sample


Try it online!

In R, things that look like operators are just functions that get special treatment from the parser.

If you redefine an operator (like -) to be some other function, it keeps the special treatment from the parser. Since - is both prefix and infix, and I need to call the sample function with both one and two arguments, I can use

`-`=sample


to get what I want.

So the code -letters is translated to sample(letters), which randomly shuffles the letters built-in. But j-1 is translated to sample(j,1), which randomly samples 1 item from the vector 1:j.

(This behaviour of the sample function depending on the number of parameters and what the first parameter is, is a huge pain in the butt in production code, so I'm happy to find a great use of its perverse nature here!)

Otherwise the code just makes the top left quadrant of the required result, replaces a random element (the j-1,j-1 bit) with a random digit (the 0:9-1 bit), and folds it out for the required symmetry. The i and the j are needed to deal with the even and odd cases.