Square-Random-Symmetrical

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
18
down vote

favorite
2












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



  1. 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 < 27 and N > 2, that is because at N <= 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.


  2. The matrix has to be both horizontally and vertically symmetrical.


  3. 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].


  4. 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.


  5. 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






share|improve this question






















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 31 at 2:30














up vote
18
down vote

favorite
2












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



  1. 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 < 27 and N > 2, that is because at N <= 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.


  2. The matrix has to be both horizontally and vertically symmetrical.


  3. 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].


  4. 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.


  5. 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






share|improve this question






















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 31 at 2:30












up vote
18
down vote

favorite
2









up vote
18
down vote

favorite
2






2





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



  1. 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 < 27 and N > 2, that is because at N <= 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.


  2. The matrix has to be both horizontally and vertically symmetrical.


  3. 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].


  4. 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.


  5. 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






share|improve this question














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



  1. 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 < 27 and N > 2, that is because at N <= 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.


  2. The matrix has to be both horizontally and vertically symmetrical.


  3. 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].


  4. 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.


  5. 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








share|improve this question













share|improve this question




share|improve this question








edited Aug 31 at 17:08

























asked Aug 29 at 20:54









DimChtz

601111




601111











  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 31 at 2:30
















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Mego♦
    Aug 31 at 2:30















Comments are not for extended discussion; this conversation has been moved to chat.
– Mego♦
Aug 31 at 2:30




Comments are not for extended discussion; this conversation has been moved to chat.
– Mego♦
Aug 31 at 2:30










14 Answers
14






active

oldest

votes

















up vote
4
down vote



accepted











Charcoal, 30 bytes



NθE⊘⊕θ⭆⊘⊕θ‽βJ‽⊘θ‽⊘θI‽χ‖OO→↓﹪θ²


Try it online! Link is to verbose version of code. If n is always even, then for 23 bytes:



NθE⊘θ⭆⊘θ‽βJ‽⊘θ‽⊘θI‽χ‖C¬


Try it online! Link is to verbose version of code. Explanation:



Nθ


Input $ n $.



E⊘θ⭆⊘θ‽β


Create an $ frac n 2 $ by $ frac n 2 $ array of random lowercase letters. This prints implicitly as a square.



J‽⊘θ‽⊘θ


Jump to a random position in the square.



I‽χ


Print a random digit.



‖C¬


Reflect horizontally and vertically to complete the matrix.






share|improve this answer



























    up vote
    11
    down vote














    R, 124 118 bytes





    function(n,i=(n+1)/2,j=n%/%2,m="[<-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y<-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.






    share|improve this answer






















    • I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
      – JayCe
      Aug 30 at 23:44










    • What a fantastic solution and explanation!
      – J.Doe
      Aug 31 at 8:57

















    up vote
    6
    down vote













    Python3, 287 bytes



    My first try at golfing something here; I'm sure someone can do far better:



    import random as rn, math as m
    n=int(input())
    x,o=m.ceil(n/2),n%2
    c=x-1-o
    f=lambda l,n: l.extend((l[::-1], l[:-1][::-1])[o])
    q=[rn.sample([chr(i) for i in range(97, 123)],x) for y in range(x)]
    q[rn.randint(0,c)][rn.randint(0,c)] = rn.randint(0,9)
    for r in q:
    f(r, n)
    f(q, n)
    print(q)


    Try it Online!



    Thanks to HyperNeurtrino, Ourous and Heiteria this shrunk down to 193 bytes (see comments). However, TFeld correctly pointed out that multiple calls to sample aren't guaranteeing at least N different characters.



    That stuff in mind, try this new version that should guarantee at least N different characters per run.



    Python3, 265 260 bytes, at least N distinct characters



    from random import *
    n=int(input())
    x=-(-n//2)
    o=n%2
    c=x+~o
    i=randint
    u=[chr(j+97)for j in range(26)]
    z,q=u[:],
    for y in [1]*x:
    shuffle(z)
    q+=[z[:x]]
    z=z[x:] if len(z[x:])>=x else u[:]
    q[i(0,c)][i(0,c)]=i(0,9)
    for r in[q]+q:r.extend(r[~o::-1])
    print(q)


    Try it online!






    share|improve this answer


















    • 1




      Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
      – HyperNeutrino
      Aug 30 at 1:56






    • 2




      You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
      – HyperNeutrino
      Aug 30 at 1:59






    • 1




      You can get it down to 236: Try it online!
      – ÎŸurous
      Aug 30 at 4:19






    • 1




      Even further, at 196: Try it online!
      – ÎŸurous
      Aug 30 at 4:58







    • 1




      The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
      – TFeld
      Aug 30 at 8:35

















    up vote
    3
    down vote














    APL (Dyalog Classic), 45 44 43 40 bytes



    thanks @Adám for -1 byte





    26(⎕a,⍺⍴⎕d)[⌈∘⊖⍨⌈∘⌽⍨⍺+@(?⊂⌊⍵÷2)?⍵⍴⍺],⍨


    Try it online!



    uses ⌈ (max) of the matrix with its reflections to make it symmetric, so it's biased towards the latter part of the alphabet



    the digit is chosen uniformly from 0...25 mod 10, so it has a small bias to lower values






    share|improve this answer


















    • 1




      ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
      – Adám
      Aug 30 at 8:59










    • @Adám clever!­­
      – ngn
      Aug 30 at 9:06











    • Yeah, I just realised.
      – Adám
      Aug 30 at 9:09










    • If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
      – Adám
      Aug 30 at 9:10











    • @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
      – ngn
      Aug 30 at 9:11

















    up vote
    3
    down vote














    Japt, 31 bytes (Fixed digit position)



    ;
    /2 c
    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv


    Try it online!





    Japt, 41 bytes (Random digit position)



    ;
    /2 c
    VÆVÆBö}ÃgMq´VÉ ,MqVÉ @Mq9îêUvÃêUv


    Try it online!




    Explanation



    ; Change to new vars
    /2 c set implicit var V equal to implicit var U / 2 rounded up
    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv Main function

    VÆ Range from 0 to V and map
    VÆ Range from 0 to V and map
    Bö}Ã return random char from alphabet
    gT0@ map upper-left corner
    Mq9Ã return random number
    ®êUv horizontal mirror
    êUv vertical mirror





    share|improve this answer






















    • Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
      – Kevin Cruijssen
      Aug 30 at 11:50











    • @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
      – Luis felipe De jesus Munoz
      Aug 30 at 11:54






    • 1




      Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
      – Kevin Cruijssen
      Aug 30 at 12:03


















    up vote
    2
    down vote














    Python 2, 259 bytes





    from random import*
    n=input();c=choice;r=range
    w,W=n/2,-~n/2
    o=n%2
    A=map(chr,r(97,123))
    l=[c(r(10))]+sample(A,n)+[c(A)for _ in' '*w*w]
    l,e=l[:w*w],l[w*w:W*W]
    shuffle(l)
    l=[l[w*i:w*-~i]+e[i:i+1]for i in range(w)]+[e[-W:]]
    for r in l+l[~o::-1]:print r+r[~o::-1]


    Try it online!






    share|improve this answer




















    • Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
      – Teck-freak
      Sep 3 at 17:09

















    up vote
    2
    down vote














    05AB1E, 29 40 38 bytes



    A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊


    +11 bytes to fix the digit being at a random position while still keeping rule 3 in mind for odd inputs..

    -2 bytes thanks to @MagicOctopusUrn, changing îï to ò and changing the position of the ».



    Try it online of verify some more test cases.



    Old (29 27 bytes) answer where the digit positions where always in the corners:



    A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊


    Try it online or verify some more test cases.



    Explanation:





    A # Take the lowercase alphabet
    .r # Randomly shuffle it
    # i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
    s # Swap so the (implicit) input is at the top of the stack
    ; # Halve the input
    # i.e. 7 → 3.5
    ò # Bankers rounding to the nearest integer
    # i.e. 3.5 → 4
    © # And save this number in the register
    n # Take its square
    # i.e. 4 → 16
    ∍ # Shorten the shuffled alphabet to that length
    # i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
    9ÝΩ # Take a random digit in the range [0,9]
    # i.e. 3
    ®Dnα # Take the difference between the saved number and its square:
    # i.e. 4 and 16 → 12
    L # Create a list in the range [1,n]
    # i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
    ʒ } # Filter this list by:
    ®%Ā # Remove any number that's divisible by the number we've saved
    # i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
    < # Decrease each by 1 (to make it 0-indexed)
    # i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
    Ω # Take a random item from this list
    # i.e. [0,1,2,3,5,6,7,9,10] → 6
    ǝ # Replace the character at this (0-indexed) position with the digit
    # i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
    ®ô # Split the string into parts of length equal to the number we've saved
    # i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
    » # Join them by new-lines (this is done implicitly in the legacy version)
    # i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovqnxr3injfgynzlbp"
    ¹Éi # If the input is odd:
    # i.e. 7 → 1 (truthy)
    .º # Intersect mirror the individual items
    # i.e. "uovqnxr3injfgynzlbp"
    # → "uovqvounxr3i3rxnjfgygfjnzlbpblz"
    .∊ # And intersect vertically mirror the whole thing
    # i.e. "uovqvounxr3i3rxnjfgygfjnzlbpblz"
    # → "uovqvounxr3i3rxnjfgygfjnzlbpblznjfgygfjnxr3i3rxnuovqvou"
    ë # Else (input was even):
    º∊ # Do the same, but with non-intersecting mirrors





    share|improve this answer






















    • You could also save 2 bytes with the legacy version since it doesn't require »
      – Emigna
      Aug 30 at 13:17










    • @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
      – Kevin Cruijssen
      Aug 30 at 14:50










    • @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
      – Kevin Cruijssen
      Aug 30 at 15:32






    • 1




      @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
      – Magic Octopus Urn
      Aug 30 at 15:36










    • @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
      – Kevin Cruijssen
      Aug 30 at 15:43

















    up vote
    2
    down vote














    C (gcc), 198 197 bytes



    Saved 1 byte thanks to ceilingcat (4 bytes actually but I lost 3 bytes fixing the bug which caused the program to print regular pattern for $N=26$.





    #define A(x)(x<n/2?x:n-1-x)
    #define R rand()
    S(n,x,y)


    Try it online!



    Explanation:



    // Coordinate conversion for symmetry
    #define A (x) (x < n / 2 ? x : n - 1 - x)
    // Get a random and seed
    #define R rand()

    S (n, x, y)






    share|improve this answer






















    • Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
      – ceilingcat
      Sep 4 at 23:11


















    up vote
    1
    down vote













    JavaScript (ES6), 213 209 206 bytes





    n=>(a=,F=(x=y=d=c=0,R=k=>Math.random()*k|0,g=y=>(r=a[y]=a[y]||)[x]=r[n+~x]=v.toString(36))=>y<n/2?F(g(y,R[v=R(m=~-n/2)<!d&x<m&y<m?R(d=10):R(26)+10]=R[v]||++c,g(n+~y))&&++x<n/2?x:+!++y,R):!d|c<n?F():a)()


    Try it online!



    Commented



    n => ( // n = input
    a = , // a = output matrix
    F = ( // F = main recursive function taking:
    x = y = // (x, y) = current coordinates
    d = c = 0, // d = digit flag; c = distinct character counter
    R = k => // R() = helper function to get a random value in [0,k[
    Math.random() * k | 0, // also used to store characters
    g = y => // g() = helper function to update the matrix
    (r = a[y] = a[y] || )[x] // with horizontal symmetry
    = r[n + ~x] = v.toString(36) // using the base-36 representation of v
    ) => //
    y < n / 2 ? // if we haven't reached the middle row(s) of the matrix:
    F( // do a recursive call to F():
    g( // invoke g() ...
    y, // ... on the current row
    R[v = // compute v = next value to be inserted
    R(m = ~-n/2) < !d & // we may insert a digit if no digit has been
    x < m & // inserted so far and the current coordinates are
    y < m ? // compatible: 2 distinct rows / 2 distinct columns
    R(d = 10) // if so, pick v in [0, 9] and update d
    : // else:
    R(26) + 10 // pick v in [10, 35] for a letter
    ] = R[v] || ++c, // set this character as used; update c accordingly
    g(n + ~y) // invoke g() on the mirror row
    ) && // end of outer call to g()
    ++x < n / 2 ? // if we haven't reached the middle column(s):
    x // use x + 1
    : // else
    +!++y, // increment y and reset x to 0
    R // explicitly pass R, as it is used for storage
    ) // end of recursive call to F()
    : // else:
    !d | c < n ? F() : a // either return the matrix or try again if it's invalid
    )() // initial call to F()





    share|improve this answer





























      up vote
      1
      down vote














      Clean, 346 312 bytes



      will golf more tomorrow



      import StdEnv,Data.List,Math.Random,System.Time,System._Unsafe
      $n#q=twice(transpose oq=zipWith((++)o reverse o drop(n-n/2*2))q q)[[(['a'..'z']++['0'..'9'])!!(c rem 36)\c<-genRandInt(toInt(accUnsafe(time)))]%(i*n/2,i*n/2+(n-1)/2)\i<-[1..(n+1)/2]]
      |length(nub(flatten q))>=n&&sum[1\c<-q|any isDigit c]==2=q= $n


      Try it online!






      share|improve this answer





























        up vote
        1
        down vote














        Python 3, 197 bytes



        As mentioned by @Emigna, doesn't work for odd values of N (I didn't understand the question properly)





        from random import*
        def m(N):M=N//2;E=reversed;R=range;B=[randint(48,57),*(sample(R(97,123),N)*N)][:M*M];shuffle(B);r=R(M);m=[k+[*E(k)]for k in[[chr(B.pop())for i in r]for j in r]];m+=E(m);return m


        Try it online!



        I do think the calls to randint() + sample() + shuffle() are too much, and getting rid of in-place shuffling would be great :)



        I'm pretty sure this part (that selects the letters & digit) could be golfed a bit more.






        share|improve this answer






















        • Doesn't seem correct for odd N.
          – Emigna
          Aug 30 at 13:50










        • Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
          – etene
          Aug 30 at 13:51






        • 1




          These are some examples of odd symmetrical matrices.
          – Emigna
          Aug 30 at 13:57










        • Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
          – etene
          Aug 30 at 13:59

















        up vote
        1
        down vote














        Python 2, 275 266 bytes





        from random import*
        def f(n):
        R=range;C=choice;A=map(chr,R(97,123));b=N=n-n/2;c=`C(R(10))`;s=[c]+sample(A,n-1)+[C(A)for i in R(N*N-n)]
        while b:shuffle(s);i=s.index(c);b=n%2>(i<N*N-N>N-1>i%N)
        a=[r+r[~(n%2)::-1]for r in[s[i::N]for i in R(N)]];return a+a[~(n%2)::-1]


        Try it online!



        Returns the array as a list of lists of characters. To satisfy Rule 1, we set up a pool of characters:



        s = [c] # the unique digit...
        + sample(A,n-1) # then sample without replacement `n-1` chars in a-z,
        # so we have `n` distinct chars
        + [C(A)for i in R(N*N-n)] # and fill out the rest with any in a-z


        The next tricky bit is rule 3: there must be exactly 2 columns and rows having a digit; this means for n odd, that the chosen digit may not appear in the middle column or middle row. Since we construct the array using a twice reflected square sub array s, that is accomplished here by using:



        while b: # to save a couple bytes, `b` is initialized 
        # to `N`, which is greater than 0.
        shuffle(s) # shuffle at least once...
        i = s.index(c) # c is the unique digit used
        b = n%2
        > # if n is even, 0>(any boolean) will be false,
        # so exit the loop; otherwise n odd, and we are
        # evaluating '1 > some boolean', which is equivalent
        # to 'not (some boolean)'
        (i<N*N-N # i is not the last column of s...
        > # shortcut for ' and ', since N*N-N is always > N-1
        N-1>i%N) # is not the last row of s


        i.e., shuffle at least once; and then, if n is odd, keep looping if the digit is in the last column or the last row of s.






        share|improve this answer





























          up vote
          1
          down vote














          Pyth, 48 bytes



          L+b_<b/Q2JmO/Q2 2jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K


          Try it out online here.



          The program is in 3 parts - definition of palindromisation function, choosing location of numeric, and main function.



          Implicit: Q=eval(input()), T=10, G=lower case alphabet

          L+b_<b/Q2 Palindromisation function
          L Define a function, y(b)
          /Q2 Half input number, rounding down
          <b Take that many elements from the start of the sequence
          _ Reverse them
          +b Prepend the unaltered sequence

          JmO/Q2 2 Choose numeric location
          O/Q2 Choose a random number between 0 and half input number
          m 2 Do the above twice, wrap in array
          J Assign to variable J

          jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K Main function
          cQ2 Divide input number by 2
          .E Round up
          K Assign the above to K
          .SG Shuffle the alphabet
          sm Q Do the above Q times, concatenate
          c K Chop the above into segments of length K
          < K Take the first K of the above
          .e Map (element, index) as (b,k) using:
          qhJk Does k equal first element of J?
          W If so...
          X b Replace in b...
          eJ ...at position <last element of J>...
          OT ...a random int less than 10
          Otherwise, b without replacement
          y Apply palindromisation to the result of the above
          y Palindromise the set of lines
          j Join on newlines, implicit print


          Using several shuffled alphabets should ensure that the number of unique characters is always more then the input number.






          share|improve this answer



























            up vote
            1
            down vote













            Python 2/Python 3, 227 bytes



            from random import*
            def m(N):n=N-N//2;r=range;C=choice;c=n*[chr(i+97)for i in r(26)];shuffle(c);c[C([i for i in r(n*(N-n))if(i+1)%n+1-N%2])]=`C(r(10))`;R=[c[i*n:i*n+n]+c[i*n:i*n+n-N%2][::-1]for i in r(n)];return R+R[::-1][N%2:]


            ungolfing a bit:



            from random import * # get 'choice' and 'shuffle'
            def matrix(N):
            n = ceil(N/2) # get the size of the base block
            # get a shuffleable lowercase alphabet
            c = [chr(i+97)for i in range(26)]
            c = n*c # make it large enough to fill the base-block
            shuffle(c) # randomize it
            digit = choice('1234567890') # get random digit string
            ## this is only needed as to prevent uneven side-length matrices
            # from having centerline digits.
            allowed_indices = [i for i in range( # get all allowed indices
            n*(N-n)) # skip those, that are in an unmirrored center-line
            if(i+1)%n # only use those that are not in the center column
            +1-N%2] # exept if there is no center column
            index = choice(allowed_indices) # get random index
            c[index]=digit # replace one field at random with a random digit
            ##
            R=
            for i in range(n):
            r = c[i*n:i*n+n] # chop to chunks sized fit for the base block
            R.append(r+r[::-1][N%2:]) # mirror skipping the center line
            return R+R[::-1][N%2:] # mirror skipping the center line and return


            Older, almost correct versions below:



            Python2, Python3, 161 bytes



            from random import *
            N=26
            n=N-N//2
            c=[chr(i+97)for i in range(26)]
            R=[ r+r[::-1][N%2:]for r in[(shuffle(c),c[:n])[1]for i in range(n)]]
            R+=R[::-1][N%2:]
            print(R)


            It seems N differing elements is only almost guarranteed.



            Python 2/Python 3, 170 bytes



            from random import*
            def m(N):n=N-N//2;r=range;c=n*[chr(i+97)for i in r(26)][:n*n];shuffle(c);R=[_+_[::-1][N%2:]for _ in[c[i*n:i*n+n]for i in r(n)]];return R+R[::-1][N%2:]


            It seems I forgot rule 3. Also somehow the [:n*n] slipped in.






            share|improve this answer






















            • Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
              – Chas Brown
              Sep 2 at 22:30










            • Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
              – Teck-freak
              Sep 3 at 0:57










            • Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
              – Chas Brown
              Sep 3 at 5:01











            • I litterally ran it over 10000 times without any error.
              – Teck-freak
              Sep 3 at 15:06










            • found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
              – Teck-freak
              Sep 3 at 15:11










            Your Answer




            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "200"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f171435%2fsquare-random-symmetrical%23new-answer', 'question_page');

            );

            Post as a guest






























            14 Answers
            14






            active

            oldest

            votes








            14 Answers
            14






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted











            Charcoal, 30 bytes



            NθE⊘⊕θ⭆⊘⊕θ‽βJ‽⊘θ‽⊘θI‽χ‖OO→↓﹪θ²


            Try it online! Link is to verbose version of code. If n is always even, then for 23 bytes:



            NθE⊘θ⭆⊘θ‽βJ‽⊘θ‽⊘θI‽χ‖C¬


            Try it online! Link is to verbose version of code. Explanation:



            Nθ


            Input $ n $.



            E⊘θ⭆⊘θ‽β


            Create an $ frac n 2 $ by $ frac n 2 $ array of random lowercase letters. This prints implicitly as a square.



            J‽⊘θ‽⊘θ


            Jump to a random position in the square.



            I‽χ


            Print a random digit.



            ‖C¬


            Reflect horizontally and vertically to complete the matrix.






            share|improve this answer
























              up vote
              4
              down vote



              accepted











              Charcoal, 30 bytes



              NθE⊘⊕θ⭆⊘⊕θ‽βJ‽⊘θ‽⊘θI‽χ‖OO→↓﹪θ²


              Try it online! Link is to verbose version of code. If n is always even, then for 23 bytes:



              NθE⊘θ⭆⊘θ‽βJ‽⊘θ‽⊘θI‽χ‖C¬


              Try it online! Link is to verbose version of code. Explanation:



              Nθ


              Input $ n $.



              E⊘θ⭆⊘θ‽β


              Create an $ frac n 2 $ by $ frac n 2 $ array of random lowercase letters. This prints implicitly as a square.



              J‽⊘θ‽⊘θ


              Jump to a random position in the square.



              I‽χ


              Print a random digit.



              ‖C¬


              Reflect horizontally and vertically to complete the matrix.






              share|improve this answer






















                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted







                Charcoal, 30 bytes



                NθE⊘⊕θ⭆⊘⊕θ‽βJ‽⊘θ‽⊘θI‽χ‖OO→↓﹪θ²


                Try it online! Link is to verbose version of code. If n is always even, then for 23 bytes:



                NθE⊘θ⭆⊘θ‽βJ‽⊘θ‽⊘θI‽χ‖C¬


                Try it online! Link is to verbose version of code. Explanation:



                Nθ


                Input $ n $.



                E⊘θ⭆⊘θ‽β


                Create an $ frac n 2 $ by $ frac n 2 $ array of random lowercase letters. This prints implicitly as a square.



                J‽⊘θ‽⊘θ


                Jump to a random position in the square.



                I‽χ


                Print a random digit.



                ‖C¬


                Reflect horizontally and vertically to complete the matrix.






                share|improve this answer













                Charcoal, 30 bytes



                NθE⊘⊕θ⭆⊘⊕θ‽βJ‽⊘θ‽⊘θI‽χ‖OO→↓﹪θ²


                Try it online! Link is to verbose version of code. If n is always even, then for 23 bytes:



                NθE⊘θ⭆⊘θ‽βJ‽⊘θ‽⊘θI‽χ‖C¬


                Try it online! Link is to verbose version of code. Explanation:



                Nθ


                Input $ n $.



                E⊘θ⭆⊘θ‽β


                Create an $ frac n 2 $ by $ frac n 2 $ array of random lowercase letters. This prints implicitly as a square.



                J‽⊘θ‽⊘θ


                Jump to a random position in the square.



                I‽χ


                Print a random digit.



                ‖C¬


                Reflect horizontally and vertically to complete the matrix.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 30 at 0:07









                Neil

                75.1k744170




                75.1k744170




















                    up vote
                    11
                    down vote














                    R, 124 118 bytes





                    function(n,i=(n+1)/2,j=n%/%2,m="[<-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y<-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.






                    share|improve this answer






















                    • I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                      – JayCe
                      Aug 30 at 23:44










                    • What a fantastic solution and explanation!
                      – J.Doe
                      Aug 31 at 8:57














                    up vote
                    11
                    down vote














                    R, 124 118 bytes





                    function(n,i=(n+1)/2,j=n%/%2,m="[<-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y<-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.






                    share|improve this answer






















                    • I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                      – JayCe
                      Aug 30 at 23:44










                    • What a fantastic solution and explanation!
                      – J.Doe
                      Aug 31 at 8:57












                    up vote
                    11
                    down vote










                    up vote
                    11
                    down vote










                    R, 124 118 bytes





                    function(n,i=(n+1)/2,j=n%/%2,m="[<-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y<-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.






                    share|improve this answer















                    R, 124 118 bytes





                    function(n,i=(n+1)/2,j=n%/%2,m="[<-"(matrix(-letters,i,i),j-1,j-1,0:9-1))cbind(y<-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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 31 at 14:49

























                    answered Aug 30 at 20:05









                    ngm

                    2,07920




                    2,07920











                    • I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                      – JayCe
                      Aug 30 at 23:44










                    • What a fantastic solution and explanation!
                      – J.Doe
                      Aug 31 at 8:57
















                    • I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                      – JayCe
                      Aug 30 at 23:44










                    • What a fantastic solution and explanation!
                      – J.Doe
                      Aug 31 at 8:57















                    I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                    – JayCe
                    Aug 30 at 23:44




                    I wish I could +2 for the great explanation and also editing the related R golfing tip answer. You can save a few more bytes
                    – JayCe
                    Aug 30 at 23:44












                    What a fantastic solution and explanation!
                    – J.Doe
                    Aug 31 at 8:57




                    What a fantastic solution and explanation!
                    – J.Doe
                    Aug 31 at 8:57










                    up vote
                    6
                    down vote













                    Python3, 287 bytes



                    My first try at golfing something here; I'm sure someone can do far better:



                    import random as rn, math as m
                    n=int(input())
                    x,o=m.ceil(n/2),n%2
                    c=x-1-o
                    f=lambda l,n: l.extend((l[::-1], l[:-1][::-1])[o])
                    q=[rn.sample([chr(i) for i in range(97, 123)],x) for y in range(x)]
                    q[rn.randint(0,c)][rn.randint(0,c)] = rn.randint(0,9)
                    for r in q:
                    f(r, n)
                    f(q, n)
                    print(q)


                    Try it Online!



                    Thanks to HyperNeurtrino, Ourous and Heiteria this shrunk down to 193 bytes (see comments). However, TFeld correctly pointed out that multiple calls to sample aren't guaranteeing at least N different characters.



                    That stuff in mind, try this new version that should guarantee at least N different characters per run.



                    Python3, 265 260 bytes, at least N distinct characters



                    from random import *
                    n=int(input())
                    x=-(-n//2)
                    o=n%2
                    c=x+~o
                    i=randint
                    u=[chr(j+97)for j in range(26)]
                    z,q=u[:],
                    for y in [1]*x:
                    shuffle(z)
                    q+=[z[:x]]
                    z=z[x:] if len(z[x:])>=x else u[:]
                    q[i(0,c)][i(0,c)]=i(0,9)
                    for r in[q]+q:r.extend(r[~o::-1])
                    print(q)


                    Try it online!






                    share|improve this answer


















                    • 1




                      Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                      – HyperNeutrino
                      Aug 30 at 1:56






                    • 2




                      You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                      – HyperNeutrino
                      Aug 30 at 1:59






                    • 1




                      You can get it down to 236: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:19






                    • 1




                      Even further, at 196: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:58







                    • 1




                      The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                      – TFeld
                      Aug 30 at 8:35














                    up vote
                    6
                    down vote













                    Python3, 287 bytes



                    My first try at golfing something here; I'm sure someone can do far better:



                    import random as rn, math as m
                    n=int(input())
                    x,o=m.ceil(n/2),n%2
                    c=x-1-o
                    f=lambda l,n: l.extend((l[::-1], l[:-1][::-1])[o])
                    q=[rn.sample([chr(i) for i in range(97, 123)],x) for y in range(x)]
                    q[rn.randint(0,c)][rn.randint(0,c)] = rn.randint(0,9)
                    for r in q:
                    f(r, n)
                    f(q, n)
                    print(q)


                    Try it Online!



                    Thanks to HyperNeurtrino, Ourous and Heiteria this shrunk down to 193 bytes (see comments). However, TFeld correctly pointed out that multiple calls to sample aren't guaranteeing at least N different characters.



                    That stuff in mind, try this new version that should guarantee at least N different characters per run.



                    Python3, 265 260 bytes, at least N distinct characters



                    from random import *
                    n=int(input())
                    x=-(-n//2)
                    o=n%2
                    c=x+~o
                    i=randint
                    u=[chr(j+97)for j in range(26)]
                    z,q=u[:],
                    for y in [1]*x:
                    shuffle(z)
                    q+=[z[:x]]
                    z=z[x:] if len(z[x:])>=x else u[:]
                    q[i(0,c)][i(0,c)]=i(0,9)
                    for r in[q]+q:r.extend(r[~o::-1])
                    print(q)


                    Try it online!






                    share|improve this answer


















                    • 1




                      Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                      – HyperNeutrino
                      Aug 30 at 1:56






                    • 2




                      You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                      – HyperNeutrino
                      Aug 30 at 1:59






                    • 1




                      You can get it down to 236: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:19






                    • 1




                      Even further, at 196: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:58







                    • 1




                      The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                      – TFeld
                      Aug 30 at 8:35












                    up vote
                    6
                    down vote










                    up vote
                    6
                    down vote









                    Python3, 287 bytes



                    My first try at golfing something here; I'm sure someone can do far better:



                    import random as rn, math as m
                    n=int(input())
                    x,o=m.ceil(n/2),n%2
                    c=x-1-o
                    f=lambda l,n: l.extend((l[::-1], l[:-1][::-1])[o])
                    q=[rn.sample([chr(i) for i in range(97, 123)],x) for y in range(x)]
                    q[rn.randint(0,c)][rn.randint(0,c)] = rn.randint(0,9)
                    for r in q:
                    f(r, n)
                    f(q, n)
                    print(q)


                    Try it Online!



                    Thanks to HyperNeurtrino, Ourous and Heiteria this shrunk down to 193 bytes (see comments). However, TFeld correctly pointed out that multiple calls to sample aren't guaranteeing at least N different characters.



                    That stuff in mind, try this new version that should guarantee at least N different characters per run.



                    Python3, 265 260 bytes, at least N distinct characters



                    from random import *
                    n=int(input())
                    x=-(-n//2)
                    o=n%2
                    c=x+~o
                    i=randint
                    u=[chr(j+97)for j in range(26)]
                    z,q=u[:],
                    for y in [1]*x:
                    shuffle(z)
                    q+=[z[:x]]
                    z=z[x:] if len(z[x:])>=x else u[:]
                    q[i(0,c)][i(0,c)]=i(0,9)
                    for r in[q]+q:r.extend(r[~o::-1])
                    print(q)


                    Try it online!






                    share|improve this answer














                    Python3, 287 bytes



                    My first try at golfing something here; I'm sure someone can do far better:



                    import random as rn, math as m
                    n=int(input())
                    x,o=m.ceil(n/2),n%2
                    c=x-1-o
                    f=lambda l,n: l.extend((l[::-1], l[:-1][::-1])[o])
                    q=[rn.sample([chr(i) for i in range(97, 123)],x) for y in range(x)]
                    q[rn.randint(0,c)][rn.randint(0,c)] = rn.randint(0,9)
                    for r in q:
                    f(r, n)
                    f(q, n)
                    print(q)


                    Try it Online!



                    Thanks to HyperNeurtrino, Ourous and Heiteria this shrunk down to 193 bytes (see comments). However, TFeld correctly pointed out that multiple calls to sample aren't guaranteeing at least N different characters.



                    That stuff in mind, try this new version that should guarantee at least N different characters per run.



                    Python3, 265 260 bytes, at least N distinct characters



                    from random import *
                    n=int(input())
                    x=-(-n//2)
                    o=n%2
                    c=x+~o
                    i=randint
                    u=[chr(j+97)for j in range(26)]
                    z,q=u[:],
                    for y in [1]*x:
                    shuffle(z)
                    q+=[z[:x]]
                    z=z[x:] if len(z[x:])>=x else u[:]
                    q[i(0,c)][i(0,c)]=i(0,9)
                    for r in[q]+q:r.extend(r[~o::-1])
                    print(q)


                    Try it online!







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 30 at 20:58

























                    answered Aug 30 at 1:51









                    souldeux

                    1614




                    1614







                    • 1




                      Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                      – HyperNeutrino
                      Aug 30 at 1:56






                    • 2




                      You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                      – HyperNeutrino
                      Aug 30 at 1:59






                    • 1




                      You can get it down to 236: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:19






                    • 1




                      Even further, at 196: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:58







                    • 1




                      The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                      – TFeld
                      Aug 30 at 8:35












                    • 1




                      Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                      – HyperNeutrino
                      Aug 30 at 1:56






                    • 2




                      You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                      – HyperNeutrino
                      Aug 30 at 1:59






                    • 1




                      You can get it down to 236: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:19






                    • 1




                      Even further, at 196: Try it online!
                      – ÎŸurous
                      Aug 30 at 4:58







                    • 1




                      The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                      – TFeld
                      Aug 30 at 8:35







                    1




                    1




                    Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                    – HyperNeutrino
                    Aug 30 at 1:56




                    Welcome to PPCG! You can golf a few of the whitespaces out; there's no need to put spaces between symbols and symbols and letters. a[:-1][::-1] is fundamentally equivalent to a[:-2::-1], and you can import random as r instead of rn, and you can move the for loop into an inline expression. Try It Online!
                    – HyperNeutrino
                    Aug 30 at 1:56




                    2




                    2




                    You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                    – HyperNeutrino
                    Aug 30 at 1:59




                    You can remove the math import by using -(-a // 2) instead of math.ceil(a / 2) which is basically negative floor-div of the negative (effectively ceiling). tio.run/##XY7LagMxDEX3/…
                    – HyperNeutrino
                    Aug 30 at 1:59




                    1




                    1




                    You can get it down to 236: Try it online!
                    – ÎŸurous
                    Aug 30 at 4:19




                    You can get it down to 236: Try it online!
                    – ÎŸurous
                    Aug 30 at 4:19




                    1




                    1




                    Even further, at 196: Try it online!
                    – ÎŸurous
                    Aug 30 at 4:58





                    Even further, at 196: Try it online!
                    – ÎŸurous
                    Aug 30 at 4:58





                    1




                    1




                    The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                    – TFeld
                    Aug 30 at 8:35




                    The multiple sample()s don't guarantee that you get at least N different characters. I managed to get [['g', 'x', 'x', 'g'], [7, 'x', 'x', 7], [7, 'x', 'x', 7], ['g', 'x', 'x', 'g']] for N=4, which only has 3 distinct chars
                    – TFeld
                    Aug 30 at 8:35










                    up vote
                    3
                    down vote














                    APL (Dyalog Classic), 45 44 43 40 bytes



                    thanks @Adám for -1 byte





                    26(⎕a,⍺⍴⎕d)[⌈∘⊖⍨⌈∘⌽⍨⍺+@(?⊂⌊⍵÷2)?⍵⍴⍺],⍨


                    Try it online!



                    uses ⌈ (max) of the matrix with its reflections to make it symmetric, so it's biased towards the latter part of the alphabet



                    the digit is chosen uniformly from 0...25 mod 10, so it has a small bias to lower values






                    share|improve this answer


















                    • 1




                      ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                      – Adám
                      Aug 30 at 8:59










                    • @Adám clever!­­
                      – ngn
                      Aug 30 at 9:06











                    • Yeah, I just realised.
                      – Adám
                      Aug 30 at 9:09










                    • If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                      – Adám
                      Aug 30 at 9:10











                    • @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                      – ngn
                      Aug 30 at 9:11














                    up vote
                    3
                    down vote














                    APL (Dyalog Classic), 45 44 43 40 bytes



                    thanks @Adám for -1 byte





                    26(⎕a,⍺⍴⎕d)[⌈∘⊖⍨⌈∘⌽⍨⍺+@(?⊂⌊⍵÷2)?⍵⍴⍺],⍨


                    Try it online!



                    uses ⌈ (max) of the matrix with its reflections to make it symmetric, so it's biased towards the latter part of the alphabet



                    the digit is chosen uniformly from 0...25 mod 10, so it has a small bias to lower values






                    share|improve this answer


















                    • 1




                      ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                      – Adám
                      Aug 30 at 8:59










                    • @Adám clever!­­
                      – ngn
                      Aug 30 at 9:06











                    • Yeah, I just realised.
                      – Adám
                      Aug 30 at 9:09










                    • If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                      – Adám
                      Aug 30 at 9:10











                    • @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                      – ngn
                      Aug 30 at 9:11












                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote










                    APL (Dyalog Classic), 45 44 43 40 bytes



                    thanks @Adám for -1 byte





                    26(⎕a,⍺⍴⎕d)[⌈∘⊖⍨⌈∘⌽⍨⍺+@(?⊂⌊⍵÷2)?⍵⍴⍺],⍨


                    Try it online!



                    uses ⌈ (max) of the matrix with its reflections to make it symmetric, so it's biased towards the latter part of the alphabet



                    the digit is chosen uniformly from 0...25 mod 10, so it has a small bias to lower values






                    share|improve this answer















                    APL (Dyalog Classic), 45 44 43 40 bytes



                    thanks @Adám for -1 byte





                    26(⎕a,⍺⍴⎕d)[⌈∘⊖⍨⌈∘⌽⍨⍺+@(?⊂⌊⍵÷2)?⍵⍴⍺],⍨


                    Try it online!



                    uses ⌈ (max) of the matrix with its reflections to make it symmetric, so it's biased towards the latter part of the alphabet



                    the digit is chosen uniformly from 0...25 mod 10, so it has a small bias to lower values







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 30 at 9:29

























                    answered Aug 30 at 8:54









                    ngn

                    6,11812256




                    6,11812256







                    • 1




                      ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                      – Adám
                      Aug 30 at 8:59










                    • @Adám clever!­­
                      – ngn
                      Aug 30 at 9:06











                    • Yeah, I just realised.
                      – Adám
                      Aug 30 at 9:09










                    • If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                      – Adám
                      Aug 30 at 9:10











                    • @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                      – ngn
                      Aug 30 at 9:11












                    • 1




                      ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                      – Adám
                      Aug 30 at 8:59










                    • @Adám clever!­­
                      – ngn
                      Aug 30 at 9:06











                    • Yeah, I just realised.
                      – Adám
                      Aug 30 at 9:09










                    • If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                      – Adám
                      Aug 30 at 9:10











                    • @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                      – ngn
                      Aug 30 at 9:11







                    1




                    1




                    ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                    – Adám
                    Aug 30 at 8:59




                    ⌊2⍴⍵÷2)?⍵ ⍵⍴26]} → ⌊⍺⍵÷2)?⍺⍵⍴26]}⍨
                    – Adám
                    Aug 30 at 8:59












                    @Adám clever!­­
                    – ngn
                    Aug 30 at 9:06





                    @Adám clever!­­
                    – ngn
                    Aug 30 at 9:06













                    Yeah, I just realised.
                    – Adám
                    Aug 30 at 9:09




                    Yeah, I just realised.
                    – Adám
                    Aug 30 at 9:09












                    If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                    – Adám
                    Aug 30 at 9:10





                    If I'm not mistaken, you can change ⌊⍺⍵÷2 → ⍺⍵.
                    – Adám
                    Aug 30 at 9:10













                    @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                    – ngn
                    Aug 30 at 9:11




                    @Adám I can't - if N is odd, the digit might end up in the centre and there'd be only 1 row/column containing it
                    – ngn
                    Aug 30 at 9:11










                    up vote
                    3
                    down vote














                    Japt, 31 bytes (Fixed digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv


                    Try it online!





                    Japt, 41 bytes (Random digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgMq´VÉ ,MqVÉ @Mq9îêUvÃêUv


                    Try it online!




                    Explanation



                    ; Change to new vars
                    /2 c set implicit var V equal to implicit var U / 2 rounded up
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv Main function

                    VÆ Range from 0 to V and map
                    VÆ Range from 0 to V and map
                    Bö}Ã return random char from alphabet
                    gT0@ map upper-left corner
                    Mq9Ã return random number
                    ®êUv horizontal mirror
                    êUv vertical mirror





                    share|improve this answer






















                    • Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                      – Kevin Cruijssen
                      Aug 30 at 11:50











                    • @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                      – Luis felipe De jesus Munoz
                      Aug 30 at 11:54






                    • 1




                      Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                      – Kevin Cruijssen
                      Aug 30 at 12:03















                    up vote
                    3
                    down vote














                    Japt, 31 bytes (Fixed digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv


                    Try it online!





                    Japt, 41 bytes (Random digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgMq´VÉ ,MqVÉ @Mq9îêUvÃêUv


                    Try it online!




                    Explanation



                    ; Change to new vars
                    /2 c set implicit var V equal to implicit var U / 2 rounded up
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv Main function

                    VÆ Range from 0 to V and map
                    VÆ Range from 0 to V and map
                    Bö}Ã return random char from alphabet
                    gT0@ map upper-left corner
                    Mq9Ã return random number
                    ®êUv horizontal mirror
                    êUv vertical mirror





                    share|improve this answer






















                    • Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                      – Kevin Cruijssen
                      Aug 30 at 11:50











                    • @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                      – Luis felipe De jesus Munoz
                      Aug 30 at 11:54






                    • 1




                      Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                      – Kevin Cruijssen
                      Aug 30 at 12:03













                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote










                    Japt, 31 bytes (Fixed digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv


                    Try it online!





                    Japt, 41 bytes (Random digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgMq´VÉ ,MqVÉ @Mq9îêUvÃêUv


                    Try it online!




                    Explanation



                    ; Change to new vars
                    /2 c set implicit var V equal to implicit var U / 2 rounded up
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv Main function

                    VÆ Range from 0 to V and map
                    VÆ Range from 0 to V and map
                    Bö}Ã return random char from alphabet
                    gT0@ map upper-left corner
                    Mq9Ã return random number
                    ®êUv horizontal mirror
                    êUv vertical mirror





                    share|improve this answer















                    Japt, 31 bytes (Fixed digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv


                    Try it online!





                    Japt, 41 bytes (Random digit position)



                    ;
                    /2 c
                    VÆVÆBö}ÃgMq´VÉ ,MqVÉ @Mq9îêUvÃêUv


                    Try it online!




                    Explanation



                    ; Change to new vars
                    /2 c set implicit var V equal to implicit var U / 2 rounded up
                    VÆVÆBö}ÃgT0@Mq9îêUvÃêUv Main function

                    VÆ Range from 0 to V and map
                    VÆ Range from 0 to V and map
                    Bö}Ã return random char from alphabet
                    gT0@ map upper-left corner
                    Mq9Ã return random number
                    ®êUv horizontal mirror
                    êUv vertical mirror






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 30 at 12:35

























                    answered Aug 29 at 22:38









                    Luis felipe De jesus Munoz

                    2,9511044




                    2,9511044











                    • Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                      – Kevin Cruijssen
                      Aug 30 at 11:50











                    • @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                      – Luis felipe De jesus Munoz
                      Aug 30 at 11:54






                    • 1




                      Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                      – Kevin Cruijssen
                      Aug 30 at 12:03

















                    • Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                      – Kevin Cruijssen
                      Aug 30 at 11:50











                    • @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                      – Luis felipe De jesus Munoz
                      Aug 30 at 11:54






                    • 1




                      Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                      – Kevin Cruijssen
                      Aug 30 at 12:03
















                    Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                    – Kevin Cruijssen
                    Aug 30 at 11:50





                    Your digits are currently always inserted at the same place. Based on the challenge, the position of the digits should be random as well (and may not be in the middle row and/or column for odd inputs due to rule 4).
                    – Kevin Cruijssen
                    Aug 30 at 11:50













                    @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                    – Luis felipe De jesus Munoz
                    Aug 30 at 11:54




                    @KevinCruijssen I dont see where the challenge say the number position must be random as well, I'll ask OP for clarification though
                    – Luis felipe De jesus Munoz
                    Aug 30 at 11:54




                    1




                    1




                    Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                    – Kevin Cruijssen
                    Aug 30 at 12:03





                    Ah, you're indeed right. I saw it's random in all other answer, so I might have falsely assumed it's mandatory. We'll see what OP says. I actually hope fixed it allowed, it would make it a lot easier to fix that problem for my prepared answer.. ;)
                    – Kevin Cruijssen
                    Aug 30 at 12:03











                    up vote
                    2
                    down vote














                    Python 2, 259 bytes





                    from random import*
                    n=input();c=choice;r=range
                    w,W=n/2,-~n/2
                    o=n%2
                    A=map(chr,r(97,123))
                    l=[c(r(10))]+sample(A,n)+[c(A)for _ in' '*w*w]
                    l,e=l[:w*w],l[w*w:W*W]
                    shuffle(l)
                    l=[l[w*i:w*-~i]+e[i:i+1]for i in range(w)]+[e[-W:]]
                    for r in l+l[~o::-1]:print r+r[~o::-1]


                    Try it online!






                    share|improve this answer




















                    • Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                      – Teck-freak
                      Sep 3 at 17:09














                    up vote
                    2
                    down vote














                    Python 2, 259 bytes





                    from random import*
                    n=input();c=choice;r=range
                    w,W=n/2,-~n/2
                    o=n%2
                    A=map(chr,r(97,123))
                    l=[c(r(10))]+sample(A,n)+[c(A)for _ in' '*w*w]
                    l,e=l[:w*w],l[w*w:W*W]
                    shuffle(l)
                    l=[l[w*i:w*-~i]+e[i:i+1]for i in range(w)]+[e[-W:]]
                    for r in l+l[~o::-1]:print r+r[~o::-1]


                    Try it online!






                    share|improve this answer




















                    • Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                      – Teck-freak
                      Sep 3 at 17:09












                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    Python 2, 259 bytes





                    from random import*
                    n=input();c=choice;r=range
                    w,W=n/2,-~n/2
                    o=n%2
                    A=map(chr,r(97,123))
                    l=[c(r(10))]+sample(A,n)+[c(A)for _ in' '*w*w]
                    l,e=l[:w*w],l[w*w:W*W]
                    shuffle(l)
                    l=[l[w*i:w*-~i]+e[i:i+1]for i in range(w)]+[e[-W:]]
                    for r in l+l[~o::-1]:print r+r[~o::-1]


                    Try it online!






                    share|improve this answer













                    Python 2, 259 bytes





                    from random import*
                    n=input();c=choice;r=range
                    w,W=n/2,-~n/2
                    o=n%2
                    A=map(chr,r(97,123))
                    l=[c(r(10))]+sample(A,n)+[c(A)for _ in' '*w*w]
                    l,e=l[:w*w],l[w*w:W*W]
                    shuffle(l)
                    l=[l[w*i:w*-~i]+e[i:i+1]for i in range(w)]+[e[-W:]]
                    for r in l+l[~o::-1]:print r+r[~o::-1]


                    Try it online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 30 at 9:20









                    TFeld

                    11.2k2833




                    11.2k2833











                    • Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                      – Teck-freak
                      Sep 3 at 17:09
















                    • Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                      – Teck-freak
                      Sep 3 at 17:09















                    Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                    – Teck-freak
                    Sep 3 at 17:09




                    Is using ints directly allowed? Cool idea on the ~ by the way. I was thinking of that too, but I'm not yet really used to it.
                    – Teck-freak
                    Sep 3 at 17:09










                    up vote
                    2
                    down vote














                    05AB1E, 29 40 38 bytes



                    A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊


                    +11 bytes to fix the digit being at a random position while still keeping rule 3 in mind for odd inputs..

                    -2 bytes thanks to @MagicOctopusUrn, changing îï to ò and changing the position of the ».



                    Try it online of verify some more test cases.



                    Old (29 27 bytes) answer where the digit positions where always in the corners:



                    A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊


                    Try it online or verify some more test cases.



                    Explanation:





                    A # Take the lowercase alphabet
                    .r # Randomly shuffle it
                    # i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
                    s # Swap so the (implicit) input is at the top of the stack
                    ; # Halve the input
                    # i.e. 7 → 3.5
                    ò # Bankers rounding to the nearest integer
                    # i.e. 3.5 → 4
                    © # And save this number in the register
                    n # Take its square
                    # i.e. 4 → 16
                    ∍ # Shorten the shuffled alphabet to that length
                    # i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
                    9ÝΩ # Take a random digit in the range [0,9]
                    # i.e. 3
                    ®Dnα # Take the difference between the saved number and its square:
                    # i.e. 4 and 16 → 12
                    L # Create a list in the range [1,n]
                    # i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
                    ʒ } # Filter this list by:
                    ®%Ā # Remove any number that's divisible by the number we've saved
                    # i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
                    < # Decrease each by 1 (to make it 0-indexed)
                    # i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
                    Ω # Take a random item from this list
                    # i.e. [0,1,2,3,5,6,7,9,10] → 6
                    ǝ # Replace the character at this (0-indexed) position with the digit
                    # i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
                    ®ô # Split the string into parts of length equal to the number we've saved
                    # i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
                    » # Join them by new-lines (this is done implicitly in the legacy version)
                    # i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovqnxr3injfgynzlbp"
                    ¹Éi # If the input is odd:
                    # i.e. 7 → 1 (truthy)
                    .º # Intersect mirror the individual items
                    # i.e. "uovqnxr3injfgynzlbp"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    .∊ # And intersect vertically mirror the whole thing
                    # i.e. "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblznjfgygfjnxr3i3rxnuovqvou"
                    ë # Else (input was even):
                    º∊ # Do the same, but with non-intersecting mirrors





                    share|improve this answer






















                    • You could also save 2 bytes with the legacy version since it doesn't require »
                      – Emigna
                      Aug 30 at 13:17










                    • @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                      – Kevin Cruijssen
                      Aug 30 at 14:50










                    • @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                      – Kevin Cruijssen
                      Aug 30 at 15:32






                    • 1




                      @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                      – Magic Octopus Urn
                      Aug 30 at 15:36










                    • @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                      – Kevin Cruijssen
                      Aug 30 at 15:43














                    up vote
                    2
                    down vote














                    05AB1E, 29 40 38 bytes



                    A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊


                    +11 bytes to fix the digit being at a random position while still keeping rule 3 in mind for odd inputs..

                    -2 bytes thanks to @MagicOctopusUrn, changing îï to ò and changing the position of the ».



                    Try it online of verify some more test cases.



                    Old (29 27 bytes) answer where the digit positions where always in the corners:



                    A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊


                    Try it online or verify some more test cases.



                    Explanation:





                    A # Take the lowercase alphabet
                    .r # Randomly shuffle it
                    # i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
                    s # Swap so the (implicit) input is at the top of the stack
                    ; # Halve the input
                    # i.e. 7 → 3.5
                    ò # Bankers rounding to the nearest integer
                    # i.e. 3.5 → 4
                    © # And save this number in the register
                    n # Take its square
                    # i.e. 4 → 16
                    ∍ # Shorten the shuffled alphabet to that length
                    # i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
                    9ÝΩ # Take a random digit in the range [0,9]
                    # i.e. 3
                    ®Dnα # Take the difference between the saved number and its square:
                    # i.e. 4 and 16 → 12
                    L # Create a list in the range [1,n]
                    # i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
                    ʒ } # Filter this list by:
                    ®%Ā # Remove any number that's divisible by the number we've saved
                    # i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
                    < # Decrease each by 1 (to make it 0-indexed)
                    # i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
                    Ω # Take a random item from this list
                    # i.e. [0,1,2,3,5,6,7,9,10] → 6
                    ǝ # Replace the character at this (0-indexed) position with the digit
                    # i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
                    ®ô # Split the string into parts of length equal to the number we've saved
                    # i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
                    » # Join them by new-lines (this is done implicitly in the legacy version)
                    # i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovqnxr3injfgynzlbp"
                    ¹Éi # If the input is odd:
                    # i.e. 7 → 1 (truthy)
                    .º # Intersect mirror the individual items
                    # i.e. "uovqnxr3injfgynzlbp"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    .∊ # And intersect vertically mirror the whole thing
                    # i.e. "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblznjfgygfjnxr3i3rxnuovqvou"
                    ë # Else (input was even):
                    º∊ # Do the same, but with non-intersecting mirrors





                    share|improve this answer






















                    • You could also save 2 bytes with the legacy version since it doesn't require »
                      – Emigna
                      Aug 30 at 13:17










                    • @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                      – Kevin Cruijssen
                      Aug 30 at 14:50










                    • @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                      – Kevin Cruijssen
                      Aug 30 at 15:32






                    • 1




                      @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                      – Magic Octopus Urn
                      Aug 30 at 15:36










                    • @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                      – Kevin Cruijssen
                      Aug 30 at 15:43












                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    05AB1E, 29 40 38 bytes



                    A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊


                    +11 bytes to fix the digit being at a random position while still keeping rule 3 in mind for odd inputs..

                    -2 bytes thanks to @MagicOctopusUrn, changing îï to ò and changing the position of the ».



                    Try it online of verify some more test cases.



                    Old (29 27 bytes) answer where the digit positions where always in the corners:



                    A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊


                    Try it online or verify some more test cases.



                    Explanation:





                    A # Take the lowercase alphabet
                    .r # Randomly shuffle it
                    # i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
                    s # Swap so the (implicit) input is at the top of the stack
                    ; # Halve the input
                    # i.e. 7 → 3.5
                    ò # Bankers rounding to the nearest integer
                    # i.e. 3.5 → 4
                    © # And save this number in the register
                    n # Take its square
                    # i.e. 4 → 16
                    ∍ # Shorten the shuffled alphabet to that length
                    # i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
                    9ÝΩ # Take a random digit in the range [0,9]
                    # i.e. 3
                    ®Dnα # Take the difference between the saved number and its square:
                    # i.e. 4 and 16 → 12
                    L # Create a list in the range [1,n]
                    # i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
                    ʒ } # Filter this list by:
                    ®%Ā # Remove any number that's divisible by the number we've saved
                    # i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
                    < # Decrease each by 1 (to make it 0-indexed)
                    # i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
                    Ω # Take a random item from this list
                    # i.e. [0,1,2,3,5,6,7,9,10] → 6
                    ǝ # Replace the character at this (0-indexed) position with the digit
                    # i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
                    ®ô # Split the string into parts of length equal to the number we've saved
                    # i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
                    » # Join them by new-lines (this is done implicitly in the legacy version)
                    # i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovqnxr3injfgynzlbp"
                    ¹Éi # If the input is odd:
                    # i.e. 7 → 1 (truthy)
                    .º # Intersect mirror the individual items
                    # i.e. "uovqnxr3injfgynzlbp"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    .∊ # And intersect vertically mirror the whole thing
                    # i.e. "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblznjfgygfjnxr3i3rxnuovqvou"
                    ë # Else (input was even):
                    º∊ # Do the same, but with non-intersecting mirrors





                    share|improve this answer















                    05AB1E, 29 40 38 bytes



                    A.rs;ò©n∍9ÝΩ®DnαLʒ®%Ā}<Ωǝ®ô»¹Éi.º.∊ëº∊


                    +11 bytes to fix the digit being at a random position while still keeping rule 3 in mind for odd inputs..

                    -2 bytes thanks to @MagicOctopusUrn, changing îï to ò and changing the position of the ».



                    Try it online of verify some more test cases.



                    Old (29 27 bytes) answer where the digit positions where always in the corners:



                    A.rs;ò©n∍¦9ÝΩì®ô»¹Éi.º.∊ëº∊


                    Try it online or verify some more test cases.



                    Explanation:





                    A # Take the lowercase alphabet
                    .r # Randomly shuffle it
                    # i.e. "abcdefghijklmnopqrstuvwxyz" → "uovqxrcijfgyzlbpmhatnkwsed"
                    s # Swap so the (implicit) input is at the top of the stack
                    ; # Halve the input
                    # i.e. 7 → 3.5
                    ò # Bankers rounding to the nearest integer
                    # i.e. 3.5 → 4
                    © # And save this number in the register
                    n # Take its square
                    # i.e. 4 → 16
                    ∍ # Shorten the shuffled alphabet to that length
                    # i.e. "uovqxrcijfgyzlbpmhatnkwsed" and 16 → "uovqxrcijfgyzlbp"
                    9ÝΩ # Take a random digit in the range [0,9]
                    # i.e. 3
                    ®Dnα # Take the difference between the saved number and its square:
                    # i.e. 4 and 16 → 12
                    L # Create a list in the range [1,n]
                    # i.e. 12 → [1,2,3,4,5,6,7,8,9,10,11,12]
                    ʒ } # Filter this list by:
                    ®%Ā # Remove any number that's divisible by the number we've saved
                    # i.e. [1,2,3,4,5,6,7,8,9,10,11,12] and 4 → [1,2,3,5,6,7,9,10,11]
                    < # Decrease each by 1 (to make it 0-indexed)
                    # i.e. [1,2,3,5,6,7,9,10,11] → [0,1,2,3,5,6,7,9,10]
                    Ω # Take a random item from this list
                    # i.e. [0,1,2,3,5,6,7,9,10] → 6
                    ǝ # Replace the character at this (0-indexed) position with the digit
                    # i.e. "uovqxrcijfgyzlbp" and 3 and 6 → "uovqxr3ijfgyzlbp"
                    ®ô # Split the string into parts of length equal to the number we've saved
                    # i.e. "uovqxr3ijfgyzlbp" and 4 → ["uovq","xr3i","jfgy","zlbp"]
                    » # Join them by new-lines (this is done implicitly in the legacy version)
                    # i.e. ["uovq","xr3i","jfgy","zlbp"] → "uovqnxr3injfgynzlbp"
                    ¹Éi # If the input is odd:
                    # i.e. 7 → 1 (truthy)
                    .º # Intersect mirror the individual items
                    # i.e. "uovqnxr3injfgynzlbp"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    .∊ # And intersect vertically mirror the whole thing
                    # i.e. "uovqvounxr3i3rxnjfgygfjnzlbpblz"
                    # → "uovqvounxr3i3rxnjfgygfjnzlbpblznjfgygfjnxr3i3rxnuovqvou"
                    ë # Else (input was even):
                    º∊ # Do the same, but with non-intersecting mirrors






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Aug 30 at 15:49

























                    answered Aug 30 at 12:25









                    Kevin Cruijssen

                    29.5k550162




                    29.5k550162











                    • You could also save 2 bytes with the legacy version since it doesn't require »
                      – Emigna
                      Aug 30 at 13:17










                    • @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                      – Kevin Cruijssen
                      Aug 30 at 14:50










                    • @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                      – Kevin Cruijssen
                      Aug 30 at 15:32






                    • 1




                      @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                      – Magic Octopus Urn
                      Aug 30 at 15:36










                    • @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                      – Kevin Cruijssen
                      Aug 30 at 15:43
















                    • You could also save 2 bytes with the legacy version since it doesn't require »
                      – Emigna
                      Aug 30 at 13:17










                    • @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                      – Kevin Cruijssen
                      Aug 30 at 14:50










                    • @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                      – Kevin Cruijssen
                      Aug 30 at 15:32






                    • 1




                      @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                      – Magic Octopus Urn
                      Aug 30 at 15:36










                    • @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                      – Kevin Cruijssen
                      Aug 30 at 15:43















                    You could also save 2 bytes with the legacy version since it doesn't require »
                    – Emigna
                    Aug 30 at 13:17




                    You could also save 2 bytes with the legacy version since it doesn't require »
                    – Emigna
                    Aug 30 at 13:17












                    @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                    – Kevin Cruijssen
                    Aug 30 at 14:50




                    @Emigna Verified with OP, and the position should indeed be random as well. Fixed for +11 bytes due to rule 3 with odd inputs.. >.> And 3 bytes could have been saved in the legacy because the ï was done implicitely as well. Unfortunately this doesn't apply to the 40-byte version because ∊ would insert instead of replace.
                    – Kevin Cruijssen
                    Aug 30 at 14:50












                    @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                    – Kevin Cruijssen
                    Aug 30 at 15:32




                    @MagicOctopusUrn The TIO you linked still contained my 29 bytes answer instead of 28, do you have the correct link? As for the failing for 2, the input is guaranteed to be 3 <= N <= 26.
                    – Kevin Cruijssen
                    Aug 30 at 15:32




                    1




                    1




                    @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                    – Magic Octopus Urn
                    Aug 30 at 15:36




                    @KevinCruijssen you're right, I'm a moron, here's the one I was working out: Try it online!
                    – Magic Octopus Urn
                    Aug 30 at 15:36












                    @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                    – Kevin Cruijssen
                    Aug 30 at 15:43




                    @MagicOctopusUrn Oh, didn't knew about that bankers rounding. That saves a byte in my current answer as well! :D And first appending a random digit and only then shuffling is a pretty smart approach as well. Not sure if it's 100% valid though, since you will always have the first n letters of the alphabet, instead of n random letters of the alphabet. And first joining by newlines and only then doing the mirrors saves a byte as well in mine. Thanks for -2 bytes! :) PS: One byte can be saved in your 28-byter by removing the trailing }. :)
                    – Kevin Cruijssen
                    Aug 30 at 15:43










                    up vote
                    2
                    down vote














                    C (gcc), 198 197 bytes



                    Saved 1 byte thanks to ceilingcat (4 bytes actually but I lost 3 bytes fixing the bug which caused the program to print regular pattern for $N=26$.





                    #define A(x)(x<n/2?x:n-1-x)
                    #define R rand()
                    S(n,x,y)


                    Try it online!



                    Explanation:



                    // Coordinate conversion for symmetry
                    #define A (x) (x < n / 2 ? x : n - 1 - x)
                    // Get a random and seed
                    #define R rand()

                    S (n, x, y)






                    share|improve this answer






















                    • Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                      – ceilingcat
                      Sep 4 at 23:11















                    up vote
                    2
                    down vote














                    C (gcc), 198 197 bytes



                    Saved 1 byte thanks to ceilingcat (4 bytes actually but I lost 3 bytes fixing the bug which caused the program to print regular pattern for $N=26$.





                    #define A(x)(x<n/2?x:n-1-x)
                    #define R rand()
                    S(n,x,y)


                    Try it online!



                    Explanation:



                    // Coordinate conversion for symmetry
                    #define A (x) (x < n / 2 ? x : n - 1 - x)
                    // Get a random and seed
                    #define R rand()

                    S (n, x, y)






                    share|improve this answer






















                    • Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                      – ceilingcat
                      Sep 4 at 23:11













                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    C (gcc), 198 197 bytes



                    Saved 1 byte thanks to ceilingcat (4 bytes actually but I lost 3 bytes fixing the bug which caused the program to print regular pattern for $N=26$.





                    #define A(x)(x<n/2?x:n-1-x)
                    #define R rand()
                    S(n,x,y)


                    Try it online!



                    Explanation:



                    // Coordinate conversion for symmetry
                    #define A (x) (x < n / 2 ? x : n - 1 - x)
                    // Get a random and seed
                    #define R rand()

                    S (n, x, y)






                    share|improve this answer















                    C (gcc), 198 197 bytes



                    Saved 1 byte thanks to ceilingcat (4 bytes actually but I lost 3 bytes fixing the bug which caused the program to print regular pattern for $N=26$.





                    #define A(x)(x<n/2?x:n-1-x)
                    #define R rand()
                    S(n,x,y)


                    Try it online!



                    Explanation:



                    // Coordinate conversion for symmetry
                    #define A (x) (x < n / 2 ? x : n - 1 - x)
                    // Get a random and seed
                    #define R rand()

                    S (n, x, y)







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 3 at 5:44

























                    answered Aug 31 at 14:48









                    Max Yekhlakov

                    2415




                    2415











                    • Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                      – ceilingcat
                      Sep 4 at 23:11

















                    • Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                      – ceilingcat
                      Sep 4 at 23:11
















                    Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                    – ceilingcat
                    Sep 4 at 23:11





                    Suggest for(s[R%y+R%y*n]=48+R%10; instead of s[R%y+n*(R%y)]=48+R%10;for(;
                    – ceilingcat
                    Sep 4 at 23:11











                    up vote
                    1
                    down vote













                    JavaScript (ES6), 213 209 206 bytes





                    n=>(a=,F=(x=y=d=c=0,R=k=>Math.random()*k|0,g=y=>(r=a[y]=a[y]||)[x]=r[n+~x]=v.toString(36))=>y<n/2?F(g(y,R[v=R(m=~-n/2)<!d&x<m&y<m?R(d=10):R(26)+10]=R[v]||++c,g(n+~y))&&++x<n/2?x:+!++y,R):!d|c<n?F():a)()


                    Try it online!



                    Commented



                    n => ( // n = input
                    a = , // a = output matrix
                    F = ( // F = main recursive function taking:
                    x = y = // (x, y) = current coordinates
                    d = c = 0, // d = digit flag; c = distinct character counter
                    R = k => // R() = helper function to get a random value in [0,k[
                    Math.random() * k | 0, // also used to store characters
                    g = y => // g() = helper function to update the matrix
                    (r = a[y] = a[y] || )[x] // with horizontal symmetry
                    = r[n + ~x] = v.toString(36) // using the base-36 representation of v
                    ) => //
                    y < n / 2 ? // if we haven't reached the middle row(s) of the matrix:
                    F( // do a recursive call to F():
                    g( // invoke g() ...
                    y, // ... on the current row
                    R[v = // compute v = next value to be inserted
                    R(m = ~-n/2) < !d & // we may insert a digit if no digit has been
                    x < m & // inserted so far and the current coordinates are
                    y < m ? // compatible: 2 distinct rows / 2 distinct columns
                    R(d = 10) // if so, pick v in [0, 9] and update d
                    : // else:
                    R(26) + 10 // pick v in [10, 35] for a letter
                    ] = R[v] || ++c, // set this character as used; update c accordingly
                    g(n + ~y) // invoke g() on the mirror row
                    ) && // end of outer call to g()
                    ++x < n / 2 ? // if we haven't reached the middle column(s):
                    x // use x + 1
                    : // else
                    +!++y, // increment y and reset x to 0
                    R // explicitly pass R, as it is used for storage
                    ) // end of recursive call to F()
                    : // else:
                    !d | c < n ? F() : a // either return the matrix or try again if it's invalid
                    )() // initial call to F()





                    share|improve this answer


























                      up vote
                      1
                      down vote













                      JavaScript (ES6), 213 209 206 bytes





                      n=>(a=,F=(x=y=d=c=0,R=k=>Math.random()*k|0,g=y=>(r=a[y]=a[y]||)[x]=r[n+~x]=v.toString(36))=>y<n/2?F(g(y,R[v=R(m=~-n/2)<!d&x<m&y<m?R(d=10):R(26)+10]=R[v]||++c,g(n+~y))&&++x<n/2?x:+!++y,R):!d|c<n?F():a)()


                      Try it online!



                      Commented



                      n => ( // n = input
                      a = , // a = output matrix
                      F = ( // F = main recursive function taking:
                      x = y = // (x, y) = current coordinates
                      d = c = 0, // d = digit flag; c = distinct character counter
                      R = k => // R() = helper function to get a random value in [0,k[
                      Math.random() * k | 0, // also used to store characters
                      g = y => // g() = helper function to update the matrix
                      (r = a[y] = a[y] || )[x] // with horizontal symmetry
                      = r[n + ~x] = v.toString(36) // using the base-36 representation of v
                      ) => //
                      y < n / 2 ? // if we haven't reached the middle row(s) of the matrix:
                      F( // do a recursive call to F():
                      g( // invoke g() ...
                      y, // ... on the current row
                      R[v = // compute v = next value to be inserted
                      R(m = ~-n/2) < !d & // we may insert a digit if no digit has been
                      x < m & // inserted so far and the current coordinates are
                      y < m ? // compatible: 2 distinct rows / 2 distinct columns
                      R(d = 10) // if so, pick v in [0, 9] and update d
                      : // else:
                      R(26) + 10 // pick v in [10, 35] for a letter
                      ] = R[v] || ++c, // set this character as used; update c accordingly
                      g(n + ~y) // invoke g() on the mirror row
                      ) && // end of outer call to g()
                      ++x < n / 2 ? // if we haven't reached the middle column(s):
                      x // use x + 1
                      : // else
                      +!++y, // increment y and reset x to 0
                      R // explicitly pass R, as it is used for storage
                      ) // end of recursive call to F()
                      : // else:
                      !d | c < n ? F() : a // either return the matrix or try again if it's invalid
                      )() // initial call to F()





                      share|improve this answer
























                        up vote
                        1
                        down vote










                        up vote
                        1
                        down vote









                        JavaScript (ES6), 213 209 206 bytes





                        n=>(a=,F=(x=y=d=c=0,R=k=>Math.random()*k|0,g=y=>(r=a[y]=a[y]||)[x]=r[n+~x]=v.toString(36))=>y<n/2?F(g(y,R[v=R(m=~-n/2)<!d&x<m&y<m?R(d=10):R(26)+10]=R[v]||++c,g(n+~y))&&++x<n/2?x:+!++y,R):!d|c<n?F():a)()


                        Try it online!



                        Commented



                        n => ( // n = input
                        a = , // a = output matrix
                        F = ( // F = main recursive function taking:
                        x = y = // (x, y) = current coordinates
                        d = c = 0, // d = digit flag; c = distinct character counter
                        R = k => // R() = helper function to get a random value in [0,k[
                        Math.random() * k | 0, // also used to store characters
                        g = y => // g() = helper function to update the matrix
                        (r = a[y] = a[y] || )[x] // with horizontal symmetry
                        = r[n + ~x] = v.toString(36) // using the base-36 representation of v
                        ) => //
                        y < n / 2 ? // if we haven't reached the middle row(s) of the matrix:
                        F( // do a recursive call to F():
                        g( // invoke g() ...
                        y, // ... on the current row
                        R[v = // compute v = next value to be inserted
                        R(m = ~-n/2) < !d & // we may insert a digit if no digit has been
                        x < m & // inserted so far and the current coordinates are
                        y < m ? // compatible: 2 distinct rows / 2 distinct columns
                        R(d = 10) // if so, pick v in [0, 9] and update d
                        : // else:
                        R(26) + 10 // pick v in [10, 35] for a letter
                        ] = R[v] || ++c, // set this character as used; update c accordingly
                        g(n + ~y) // invoke g() on the mirror row
                        ) && // end of outer call to g()
                        ++x < n / 2 ? // if we haven't reached the middle column(s):
                        x // use x + 1
                        : // else
                        +!++y, // increment y and reset x to 0
                        R // explicitly pass R, as it is used for storage
                        ) // end of recursive call to F()
                        : // else:
                        !d | c < n ? F() : a // either return the matrix or try again if it's invalid
                        )() // initial call to F()





                        share|improve this answer














                        JavaScript (ES6), 213 209 206 bytes





                        n=>(a=,F=(x=y=d=c=0,R=k=>Math.random()*k|0,g=y=>(r=a[y]=a[y]||)[x]=r[n+~x]=v.toString(36))=>y<n/2?F(g(y,R[v=R(m=~-n/2)<!d&x<m&y<m?R(d=10):R(26)+10]=R[v]||++c,g(n+~y))&&++x<n/2?x:+!++y,R):!d|c<n?F():a)()


                        Try it online!



                        Commented



                        n => ( // n = input
                        a = , // a = output matrix
                        F = ( // F = main recursive function taking:
                        x = y = // (x, y) = current coordinates
                        d = c = 0, // d = digit flag; c = distinct character counter
                        R = k => // R() = helper function to get a random value in [0,k[
                        Math.random() * k | 0, // also used to store characters
                        g = y => // g() = helper function to update the matrix
                        (r = a[y] = a[y] || )[x] // with horizontal symmetry
                        = r[n + ~x] = v.toString(36) // using the base-36 representation of v
                        ) => //
                        y < n / 2 ? // if we haven't reached the middle row(s) of the matrix:
                        F( // do a recursive call to F():
                        g( // invoke g() ...
                        y, // ... on the current row
                        R[v = // compute v = next value to be inserted
                        R(m = ~-n/2) < !d & // we may insert a digit if no digit has been
                        x < m & // inserted so far and the current coordinates are
                        y < m ? // compatible: 2 distinct rows / 2 distinct columns
                        R(d = 10) // if so, pick v in [0, 9] and update d
                        : // else:
                        R(26) + 10 // pick v in [10, 35] for a letter
                        ] = R[v] || ++c, // set this character as used; update c accordingly
                        g(n + ~y) // invoke g() on the mirror row
                        ) && // end of outer call to g()
                        ++x < n / 2 ? // if we haven't reached the middle column(s):
                        x // use x + 1
                        : // else
                        +!++y, // increment y and reset x to 0
                        R // explicitly pass R, as it is used for storage
                        ) // end of recursive call to F()
                        : // else:
                        !d | c < n ? F() : a // either return the matrix or try again if it's invalid
                        )() // initial call to F()






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Aug 30 at 10:26

























                        answered Aug 30 at 8:29









                        Arnauld

                        63.6k580268




                        63.6k580268




















                            up vote
                            1
                            down vote














                            Clean, 346 312 bytes



                            will golf more tomorrow



                            import StdEnv,Data.List,Math.Random,System.Time,System._Unsafe
                            $n#q=twice(transpose oq=zipWith((++)o reverse o drop(n-n/2*2))q q)[[(['a'..'z']++['0'..'9'])!!(c rem 36)\c<-genRandInt(toInt(accUnsafe(time)))]%(i*n/2,i*n/2+(n-1)/2)\i<-[1..(n+1)/2]]
                            |length(nub(flatten q))>=n&&sum[1\c<-q|any isDigit c]==2=q= $n


                            Try it online!






                            share|improve this answer


























                              up vote
                              1
                              down vote














                              Clean, 346 312 bytes



                              will golf more tomorrow



                              import StdEnv,Data.List,Math.Random,System.Time,System._Unsafe
                              $n#q=twice(transpose oq=zipWith((++)o reverse o drop(n-n/2*2))q q)[[(['a'..'z']++['0'..'9'])!!(c rem 36)\c<-genRandInt(toInt(accUnsafe(time)))]%(i*n/2,i*n/2+(n-1)/2)\i<-[1..(n+1)/2]]
                              |length(nub(flatten q))>=n&&sum[1\c<-q|any isDigit c]==2=q= $n


                              Try it online!






                              share|improve this answer
























                                up vote
                                1
                                down vote










                                up vote
                                1
                                down vote










                                Clean, 346 312 bytes



                                will golf more tomorrow



                                import StdEnv,Data.List,Math.Random,System.Time,System._Unsafe
                                $n#q=twice(transpose oq=zipWith((++)o reverse o drop(n-n/2*2))q q)[[(['a'..'z']++['0'..'9'])!!(c rem 36)\c<-genRandInt(toInt(accUnsafe(time)))]%(i*n/2,i*n/2+(n-1)/2)\i<-[1..(n+1)/2]]
                                |length(nub(flatten q))>=n&&sum[1\c<-q|any isDigit c]==2=q= $n


                                Try it online!






                                share|improve this answer















                                Clean, 346 312 bytes



                                will golf more tomorrow



                                import StdEnv,Data.List,Math.Random,System.Time,System._Unsafe
                                $n#q=twice(transpose oq=zipWith((++)o reverse o drop(n-n/2*2))q q)[[(['a'..'z']++['0'..'9'])!!(c rem 36)\c<-genRandInt(toInt(accUnsafe(time)))]%(i*n/2,i*n/2+(n-1)/2)\i<-[1..(n+1)/2]]
                                |length(nub(flatten q))>=n&&sum[1\c<-q|any isDigit c]==2=q= $n


                                Try it online!







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Aug 30 at 12:26

























                                answered Aug 30 at 1:36









                                Οurous

                                5,2031931




                                5,2031931




















                                    up vote
                                    1
                                    down vote














                                    Python 3, 197 bytes



                                    As mentioned by @Emigna, doesn't work for odd values of N (I didn't understand the question properly)





                                    from random import*
                                    def m(N):M=N//2;E=reversed;R=range;B=[randint(48,57),*(sample(R(97,123),N)*N)][:M*M];shuffle(B);r=R(M);m=[k+[*E(k)]for k in[[chr(B.pop())for i in r]for j in r]];m+=E(m);return m


                                    Try it online!



                                    I do think the calls to randint() + sample() + shuffle() are too much, and getting rid of in-place shuffling would be great :)



                                    I'm pretty sure this part (that selects the letters & digit) could be golfed a bit more.






                                    share|improve this answer






















                                    • Doesn't seem correct for odd N.
                                      – Emigna
                                      Aug 30 at 13:50










                                    • Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                      – etene
                                      Aug 30 at 13:51






                                    • 1




                                      These are some examples of odd symmetrical matrices.
                                      – Emigna
                                      Aug 30 at 13:57










                                    • Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                      – etene
                                      Aug 30 at 13:59














                                    up vote
                                    1
                                    down vote














                                    Python 3, 197 bytes



                                    As mentioned by @Emigna, doesn't work for odd values of N (I didn't understand the question properly)





                                    from random import*
                                    def m(N):M=N//2;E=reversed;R=range;B=[randint(48,57),*(sample(R(97,123),N)*N)][:M*M];shuffle(B);r=R(M);m=[k+[*E(k)]for k in[[chr(B.pop())for i in r]for j in r]];m+=E(m);return m


                                    Try it online!



                                    I do think the calls to randint() + sample() + shuffle() are too much, and getting rid of in-place shuffling would be great :)



                                    I'm pretty sure this part (that selects the letters & digit) could be golfed a bit more.






                                    share|improve this answer






















                                    • Doesn't seem correct for odd N.
                                      – Emigna
                                      Aug 30 at 13:50










                                    • Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                      – etene
                                      Aug 30 at 13:51






                                    • 1




                                      These are some examples of odd symmetrical matrices.
                                      – Emigna
                                      Aug 30 at 13:57










                                    • Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                      – etene
                                      Aug 30 at 13:59












                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote










                                    Python 3, 197 bytes



                                    As mentioned by @Emigna, doesn't work for odd values of N (I didn't understand the question properly)





                                    from random import*
                                    def m(N):M=N//2;E=reversed;R=range;B=[randint(48,57),*(sample(R(97,123),N)*N)][:M*M];shuffle(B);r=R(M);m=[k+[*E(k)]for k in[[chr(B.pop())for i in r]for j in r]];m+=E(m);return m


                                    Try it online!



                                    I do think the calls to randint() + sample() + shuffle() are too much, and getting rid of in-place shuffling would be great :)



                                    I'm pretty sure this part (that selects the letters & digit) could be golfed a bit more.






                                    share|improve this answer















                                    Python 3, 197 bytes



                                    As mentioned by @Emigna, doesn't work for odd values of N (I didn't understand the question properly)





                                    from random import*
                                    def m(N):M=N//2;E=reversed;R=range;B=[randint(48,57),*(sample(R(97,123),N)*N)][:M*M];shuffle(B);r=R(M);m=[k+[*E(k)]for k in[[chr(B.pop())for i in r]for j in r]];m+=E(m);return m


                                    Try it online!



                                    I do think the calls to randint() + sample() + shuffle() are too much, and getting rid of in-place shuffling would be great :)



                                    I'm pretty sure this part (that selects the letters & digit) could be golfed a bit more.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Aug 30 at 14:02

























                                    answered Aug 30 at 12:59









                                    etene

                                    4487




                                    4487











                                    • Doesn't seem correct for odd N.
                                      – Emigna
                                      Aug 30 at 13:50










                                    • Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                      – etene
                                      Aug 30 at 13:51






                                    • 1




                                      These are some examples of odd symmetrical matrices.
                                      – Emigna
                                      Aug 30 at 13:57










                                    • Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                      – etene
                                      Aug 30 at 13:59
















                                    • Doesn't seem correct for odd N.
                                      – Emigna
                                      Aug 30 at 13:50










                                    • Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                      – etene
                                      Aug 30 at 13:51






                                    • 1




                                      These are some examples of odd symmetrical matrices.
                                      – Emigna
                                      Aug 30 at 13:57










                                    • Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                      – etene
                                      Aug 30 at 13:59















                                    Doesn't seem correct for odd N.
                                    – Emigna
                                    Aug 30 at 13:50




                                    Doesn't seem correct for odd N.
                                    – Emigna
                                    Aug 30 at 13:50












                                    Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                    – etene
                                    Aug 30 at 13:51




                                    Damn, I had just assumed N would always be even since I don't get how the matrix could be symmetrical if it's odd !
                                    – etene
                                    Aug 30 at 13:51




                                    1




                                    1




                                    These are some examples of odd symmetrical matrices.
                                    – Emigna
                                    Aug 30 at 13:57




                                    These are some examples of odd symmetrical matrices.
                                    – Emigna
                                    Aug 30 at 13:57












                                    Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                    – etene
                                    Aug 30 at 13:59




                                    Okay, thanks, I hadn't seen it that way ! Well I guess my answer is worthless as is then.
                                    – etene
                                    Aug 30 at 13:59










                                    up vote
                                    1
                                    down vote














                                    Python 2, 275 266 bytes





                                    from random import*
                                    def f(n):
                                    R=range;C=choice;A=map(chr,R(97,123));b=N=n-n/2;c=`C(R(10))`;s=[c]+sample(A,n-1)+[C(A)for i in R(N*N-n)]
                                    while b:shuffle(s);i=s.index(c);b=n%2>(i<N*N-N>N-1>i%N)
                                    a=[r+r[~(n%2)::-1]for r in[s[i::N]for i in R(N)]];return a+a[~(n%2)::-1]


                                    Try it online!



                                    Returns the array as a list of lists of characters. To satisfy Rule 1, we set up a pool of characters:



                                    s = [c] # the unique digit...
                                    + sample(A,n-1) # then sample without replacement `n-1` chars in a-z,
                                    # so we have `n` distinct chars
                                    + [C(A)for i in R(N*N-n)] # and fill out the rest with any in a-z


                                    The next tricky bit is rule 3: there must be exactly 2 columns and rows having a digit; this means for n odd, that the chosen digit may not appear in the middle column or middle row. Since we construct the array using a twice reflected square sub array s, that is accomplished here by using:



                                    while b: # to save a couple bytes, `b` is initialized 
                                    # to `N`, which is greater than 0.
                                    shuffle(s) # shuffle at least once...
                                    i = s.index(c) # c is the unique digit used
                                    b = n%2
                                    > # if n is even, 0>(any boolean) will be false,
                                    # so exit the loop; otherwise n odd, and we are
                                    # evaluating '1 > some boolean', which is equivalent
                                    # to 'not (some boolean)'
                                    (i<N*N-N # i is not the last column of s...
                                    > # shortcut for ' and ', since N*N-N is always > N-1
                                    N-1>i%N) # is not the last row of s


                                    i.e., shuffle at least once; and then, if n is odd, keep looping if the digit is in the last column or the last row of s.






                                    share|improve this answer


























                                      up vote
                                      1
                                      down vote














                                      Python 2, 275 266 bytes





                                      from random import*
                                      def f(n):
                                      R=range;C=choice;A=map(chr,R(97,123));b=N=n-n/2;c=`C(R(10))`;s=[c]+sample(A,n-1)+[C(A)for i in R(N*N-n)]
                                      while b:shuffle(s);i=s.index(c);b=n%2>(i<N*N-N>N-1>i%N)
                                      a=[r+r[~(n%2)::-1]for r in[s[i::N]for i in R(N)]];return a+a[~(n%2)::-1]


                                      Try it online!



                                      Returns the array as a list of lists of characters. To satisfy Rule 1, we set up a pool of characters:



                                      s = [c] # the unique digit...
                                      + sample(A,n-1) # then sample without replacement `n-1` chars in a-z,
                                      # so we have `n` distinct chars
                                      + [C(A)for i in R(N*N-n)] # and fill out the rest with any in a-z


                                      The next tricky bit is rule 3: there must be exactly 2 columns and rows having a digit; this means for n odd, that the chosen digit may not appear in the middle column or middle row. Since we construct the array using a twice reflected square sub array s, that is accomplished here by using:



                                      while b: # to save a couple bytes, `b` is initialized 
                                      # to `N`, which is greater than 0.
                                      shuffle(s) # shuffle at least once...
                                      i = s.index(c) # c is the unique digit used
                                      b = n%2
                                      > # if n is even, 0>(any boolean) will be false,
                                      # so exit the loop; otherwise n odd, and we are
                                      # evaluating '1 > some boolean', which is equivalent
                                      # to 'not (some boolean)'
                                      (i<N*N-N # i is not the last column of s...
                                      > # shortcut for ' and ', since N*N-N is always > N-1
                                      N-1>i%N) # is not the last row of s


                                      i.e., shuffle at least once; and then, if n is odd, keep looping if the digit is in the last column or the last row of s.






                                      share|improve this answer
























                                        up vote
                                        1
                                        down vote










                                        up vote
                                        1
                                        down vote










                                        Python 2, 275 266 bytes





                                        from random import*
                                        def f(n):
                                        R=range;C=choice;A=map(chr,R(97,123));b=N=n-n/2;c=`C(R(10))`;s=[c]+sample(A,n-1)+[C(A)for i in R(N*N-n)]
                                        while b:shuffle(s);i=s.index(c);b=n%2>(i<N*N-N>N-1>i%N)
                                        a=[r+r[~(n%2)::-1]for r in[s[i::N]for i in R(N)]];return a+a[~(n%2)::-1]


                                        Try it online!



                                        Returns the array as a list of lists of characters. To satisfy Rule 1, we set up a pool of characters:



                                        s = [c] # the unique digit...
                                        + sample(A,n-1) # then sample without replacement `n-1` chars in a-z,
                                        # so we have `n` distinct chars
                                        + [C(A)for i in R(N*N-n)] # and fill out the rest with any in a-z


                                        The next tricky bit is rule 3: there must be exactly 2 columns and rows having a digit; this means for n odd, that the chosen digit may not appear in the middle column or middle row. Since we construct the array using a twice reflected square sub array s, that is accomplished here by using:



                                        while b: # to save a couple bytes, `b` is initialized 
                                        # to `N`, which is greater than 0.
                                        shuffle(s) # shuffle at least once...
                                        i = s.index(c) # c is the unique digit used
                                        b = n%2
                                        > # if n is even, 0>(any boolean) will be false,
                                        # so exit the loop; otherwise n odd, and we are
                                        # evaluating '1 > some boolean', which is equivalent
                                        # to 'not (some boolean)'
                                        (i<N*N-N # i is not the last column of s...
                                        > # shortcut for ' and ', since N*N-N is always > N-1
                                        N-1>i%N) # is not the last row of s


                                        i.e., shuffle at least once; and then, if n is odd, keep looping if the digit is in the last column or the last row of s.






                                        share|improve this answer















                                        Python 2, 275 266 bytes





                                        from random import*
                                        def f(n):
                                        R=range;C=choice;A=map(chr,R(97,123));b=N=n-n/2;c=`C(R(10))`;s=[c]+sample(A,n-1)+[C(A)for i in R(N*N-n)]
                                        while b:shuffle(s);i=s.index(c);b=n%2>(i<N*N-N>N-1>i%N)
                                        a=[r+r[~(n%2)::-1]for r in[s[i::N]for i in R(N)]];return a+a[~(n%2)::-1]


                                        Try it online!



                                        Returns the array as a list of lists of characters. To satisfy Rule 1, we set up a pool of characters:



                                        s = [c] # the unique digit...
                                        + sample(A,n-1) # then sample without replacement `n-1` chars in a-z,
                                        # so we have `n` distinct chars
                                        + [C(A)for i in R(N*N-n)] # and fill out the rest with any in a-z


                                        The next tricky bit is rule 3: there must be exactly 2 columns and rows having a digit; this means for n odd, that the chosen digit may not appear in the middle column or middle row. Since we construct the array using a twice reflected square sub array s, that is accomplished here by using:



                                        while b: # to save a couple bytes, `b` is initialized 
                                        # to `N`, which is greater than 0.
                                        shuffle(s) # shuffle at least once...
                                        i = s.index(c) # c is the unique digit used
                                        b = n%2
                                        > # if n is even, 0>(any boolean) will be false,
                                        # so exit the loop; otherwise n odd, and we are
                                        # evaluating '1 > some boolean', which is equivalent
                                        # to 'not (some boolean)'
                                        (i<N*N-N # i is not the last column of s...
                                        > # shortcut for ' and ', since N*N-N is always > N-1
                                        N-1>i%N) # is not the last row of s


                                        i.e., shuffle at least once; and then, if n is odd, keep looping if the digit is in the last column or the last row of s.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 3 at 6:19

























                                        answered Sep 3 at 4:58









                                        Chas Brown

                                        4,1361319




                                        4,1361319




















                                            up vote
                                            1
                                            down vote














                                            Pyth, 48 bytes



                                            L+b_<b/Q2JmO/Q2 2jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K


                                            Try it out online here.



                                            The program is in 3 parts - definition of palindromisation function, choosing location of numeric, and main function.



                                            Implicit: Q=eval(input()), T=10, G=lower case alphabet

                                            L+b_<b/Q2 Palindromisation function
                                            L Define a function, y(b)
                                            /Q2 Half input number, rounding down
                                            <b Take that many elements from the start of the sequence
                                            _ Reverse them
                                            +b Prepend the unaltered sequence

                                            JmO/Q2 2 Choose numeric location
                                            O/Q2 Choose a random number between 0 and half input number
                                            m 2 Do the above twice, wrap in array
                                            J Assign to variable J

                                            jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K Main function
                                            cQ2 Divide input number by 2
                                            .E Round up
                                            K Assign the above to K
                                            .SG Shuffle the alphabet
                                            sm Q Do the above Q times, concatenate
                                            c K Chop the above into segments of length K
                                            < K Take the first K of the above
                                            .e Map (element, index) as (b,k) using:
                                            qhJk Does k equal first element of J?
                                            W If so...
                                            X b Replace in b...
                                            eJ ...at position <last element of J>...
                                            OT ...a random int less than 10
                                            Otherwise, b without replacement
                                            y Apply palindromisation to the result of the above
                                            y Palindromise the set of lines
                                            j Join on newlines, implicit print


                                            Using several shuffled alphabets should ensure that the number of unique characters is always more then the input number.






                                            share|improve this answer
























                                              up vote
                                              1
                                              down vote














                                              Pyth, 48 bytes



                                              L+b_<b/Q2JmO/Q2 2jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K


                                              Try it out online here.



                                              The program is in 3 parts - definition of palindromisation function, choosing location of numeric, and main function.



                                              Implicit: Q=eval(input()), T=10, G=lower case alphabet

                                              L+b_<b/Q2 Palindromisation function
                                              L Define a function, y(b)
                                              /Q2 Half input number, rounding down
                                              <b Take that many elements from the start of the sequence
                                              _ Reverse them
                                              +b Prepend the unaltered sequence

                                              JmO/Q2 2 Choose numeric location
                                              O/Q2 Choose a random number between 0 and half input number
                                              m 2 Do the above twice, wrap in array
                                              J Assign to variable J

                                              jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K Main function
                                              cQ2 Divide input number by 2
                                              .E Round up
                                              K Assign the above to K
                                              .SG Shuffle the alphabet
                                              sm Q Do the above Q times, concatenate
                                              c K Chop the above into segments of length K
                                              < K Take the first K of the above
                                              .e Map (element, index) as (b,k) using:
                                              qhJk Does k equal first element of J?
                                              W If so...
                                              X b Replace in b...
                                              eJ ...at position <last element of J>...
                                              OT ...a random int less than 10
                                              Otherwise, b without replacement
                                              y Apply palindromisation to the result of the above
                                              y Palindromise the set of lines
                                              j Join on newlines, implicit print


                                              Using several shuffled alphabets should ensure that the number of unique characters is always more then the input number.






                                              share|improve this answer






















                                                up vote
                                                1
                                                down vote










                                                up vote
                                                1
                                                down vote










                                                Pyth, 48 bytes



                                                L+b_<b/Q2JmO/Q2 2jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K


                                                Try it out online here.



                                                The program is in 3 parts - definition of palindromisation function, choosing location of numeric, and main function.



                                                Implicit: Q=eval(input()), T=10, G=lower case alphabet

                                                L+b_<b/Q2 Palindromisation function
                                                L Define a function, y(b)
                                                /Q2 Half input number, rounding down
                                                <b Take that many elements from the start of the sequence
                                                _ Reverse them
                                                +b Prepend the unaltered sequence

                                                JmO/Q2 2 Choose numeric location
                                                O/Q2 Choose a random number between 0 and half input number
                                                m 2 Do the above twice, wrap in array
                                                J Assign to variable J

                                                jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K Main function
                                                cQ2 Divide input number by 2
                                                .E Round up
                                                K Assign the above to K
                                                .SG Shuffle the alphabet
                                                sm Q Do the above Q times, concatenate
                                                c K Chop the above into segments of length K
                                                < K Take the first K of the above
                                                .e Map (element, index) as (b,k) using:
                                                qhJk Does k equal first element of J?
                                                W If so...
                                                X b Replace in b...
                                                eJ ...at position <last element of J>...
                                                OT ...a random int less than 10
                                                Otherwise, b without replacement
                                                y Apply palindromisation to the result of the above
                                                y Palindromise the set of lines
                                                j Join on newlines, implicit print


                                                Using several shuffled alphabets should ensure that the number of unique characters is always more then the input number.






                                                share|improve this answer













                                                Pyth, 48 bytes



                                                L+b_<b/Q2JmO/Q2 2jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K


                                                Try it out online here.



                                                The program is in 3 parts - definition of palindromisation function, choosing location of numeric, and main function.



                                                Implicit: Q=eval(input()), T=10, G=lower case alphabet

                                                L+b_<b/Q2 Palindromisation function
                                                L Define a function, y(b)
                                                /Q2 Half input number, rounding down
                                                <b Take that many elements from the start of the sequence
                                                _ Reverse them
                                                +b Prepend the unaltered sequence

                                                JmO/Q2 2 Choose numeric location
                                                O/Q2 Choose a random number between 0 and half input number
                                                m 2 Do the above twice, wrap in array
                                                J Assign to variable J

                                                jy.eyXWqhJkbeJOT<csm.SGQK.EcQ2K Main function
                                                cQ2 Divide input number by 2
                                                .E Round up
                                                K Assign the above to K
                                                .SG Shuffle the alphabet
                                                sm Q Do the above Q times, concatenate
                                                c K Chop the above into segments of length K
                                                < K Take the first K of the above
                                                .e Map (element, index) as (b,k) using:
                                                qhJk Does k equal first element of J?
                                                W If so...
                                                X b Replace in b...
                                                eJ ...at position <last element of J>...
                                                OT ...a random int less than 10
                                                Otherwise, b without replacement
                                                y Apply palindromisation to the result of the above
                                                y Palindromise the set of lines
                                                j Join on newlines, implicit print


                                                Using several shuffled alphabets should ensure that the number of unique characters is always more then the input number.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Sep 3 at 9:38









                                                Sok

                                                2,851722




                                                2,851722




















                                                    up vote
                                                    1
                                                    down vote













                                                    Python 2/Python 3, 227 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;C=choice;c=n*[chr(i+97)for i in r(26)];shuffle(c);c[C([i for i in r(n*(N-n))if(i+1)%n+1-N%2])]=`C(r(10))`;R=[c[i*n:i*n+n]+c[i*n:i*n+n-N%2][::-1]for i in r(n)];return R+R[::-1][N%2:]


                                                    ungolfing a bit:



                                                    from random import * # get 'choice' and 'shuffle'
                                                    def matrix(N):
                                                    n = ceil(N/2) # get the size of the base block
                                                    # get a shuffleable lowercase alphabet
                                                    c = [chr(i+97)for i in range(26)]
                                                    c = n*c # make it large enough to fill the base-block
                                                    shuffle(c) # randomize it
                                                    digit = choice('1234567890') # get random digit string
                                                    ## this is only needed as to prevent uneven side-length matrices
                                                    # from having centerline digits.
                                                    allowed_indices = [i for i in range( # get all allowed indices
                                                    n*(N-n)) # skip those, that are in an unmirrored center-line
                                                    if(i+1)%n # only use those that are not in the center column
                                                    +1-N%2] # exept if there is no center column
                                                    index = choice(allowed_indices) # get random index
                                                    c[index]=digit # replace one field at random with a random digit
                                                    ##
                                                    R=
                                                    for i in range(n):
                                                    r = c[i*n:i*n+n] # chop to chunks sized fit for the base block
                                                    R.append(r+r[::-1][N%2:]) # mirror skipping the center line
                                                    return R+R[::-1][N%2:] # mirror skipping the center line and return


                                                    Older, almost correct versions below:



                                                    Python2, Python3, 161 bytes



                                                    from random import *
                                                    N=26
                                                    n=N-N//2
                                                    c=[chr(i+97)for i in range(26)]
                                                    R=[ r+r[::-1][N%2:]for r in[(shuffle(c),c[:n])[1]for i in range(n)]]
                                                    R+=R[::-1][N%2:]
                                                    print(R)


                                                    It seems N differing elements is only almost guarranteed.



                                                    Python 2/Python 3, 170 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;c=n*[chr(i+97)for i in r(26)][:n*n];shuffle(c);R=[_+_[::-1][N%2:]for _ in[c[i*n:i*n+n]for i in r(n)]];return R+R[::-1][N%2:]


                                                    It seems I forgot rule 3. Also somehow the [:n*n] slipped in.






                                                    share|improve this answer






















                                                    • Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                      – Chas Brown
                                                      Sep 2 at 22:30










                                                    • Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                      – Teck-freak
                                                      Sep 3 at 0:57










                                                    • Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                      – Chas Brown
                                                      Sep 3 at 5:01











                                                    • I litterally ran it over 10000 times without any error.
                                                      – Teck-freak
                                                      Sep 3 at 15:06










                                                    • found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                      – Teck-freak
                                                      Sep 3 at 15:11














                                                    up vote
                                                    1
                                                    down vote













                                                    Python 2/Python 3, 227 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;C=choice;c=n*[chr(i+97)for i in r(26)];shuffle(c);c[C([i for i in r(n*(N-n))if(i+1)%n+1-N%2])]=`C(r(10))`;R=[c[i*n:i*n+n]+c[i*n:i*n+n-N%2][::-1]for i in r(n)];return R+R[::-1][N%2:]


                                                    ungolfing a bit:



                                                    from random import * # get 'choice' and 'shuffle'
                                                    def matrix(N):
                                                    n = ceil(N/2) # get the size of the base block
                                                    # get a shuffleable lowercase alphabet
                                                    c = [chr(i+97)for i in range(26)]
                                                    c = n*c # make it large enough to fill the base-block
                                                    shuffle(c) # randomize it
                                                    digit = choice('1234567890') # get random digit string
                                                    ## this is only needed as to prevent uneven side-length matrices
                                                    # from having centerline digits.
                                                    allowed_indices = [i for i in range( # get all allowed indices
                                                    n*(N-n)) # skip those, that are in an unmirrored center-line
                                                    if(i+1)%n # only use those that are not in the center column
                                                    +1-N%2] # exept if there is no center column
                                                    index = choice(allowed_indices) # get random index
                                                    c[index]=digit # replace one field at random with a random digit
                                                    ##
                                                    R=
                                                    for i in range(n):
                                                    r = c[i*n:i*n+n] # chop to chunks sized fit for the base block
                                                    R.append(r+r[::-1][N%2:]) # mirror skipping the center line
                                                    return R+R[::-1][N%2:] # mirror skipping the center line and return


                                                    Older, almost correct versions below:



                                                    Python2, Python3, 161 bytes



                                                    from random import *
                                                    N=26
                                                    n=N-N//2
                                                    c=[chr(i+97)for i in range(26)]
                                                    R=[ r+r[::-1][N%2:]for r in[(shuffle(c),c[:n])[1]for i in range(n)]]
                                                    R+=R[::-1][N%2:]
                                                    print(R)


                                                    It seems N differing elements is only almost guarranteed.



                                                    Python 2/Python 3, 170 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;c=n*[chr(i+97)for i in r(26)][:n*n];shuffle(c);R=[_+_[::-1][N%2:]for _ in[c[i*n:i*n+n]for i in r(n)]];return R+R[::-1][N%2:]


                                                    It seems I forgot rule 3. Also somehow the [:n*n] slipped in.






                                                    share|improve this answer






















                                                    • Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                      – Chas Brown
                                                      Sep 2 at 22:30










                                                    • Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                      – Teck-freak
                                                      Sep 3 at 0:57










                                                    • Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                      – Chas Brown
                                                      Sep 3 at 5:01











                                                    • I litterally ran it over 10000 times without any error.
                                                      – Teck-freak
                                                      Sep 3 at 15:06










                                                    • found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                      – Teck-freak
                                                      Sep 3 at 15:11












                                                    up vote
                                                    1
                                                    down vote










                                                    up vote
                                                    1
                                                    down vote









                                                    Python 2/Python 3, 227 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;C=choice;c=n*[chr(i+97)for i in r(26)];shuffle(c);c[C([i for i in r(n*(N-n))if(i+1)%n+1-N%2])]=`C(r(10))`;R=[c[i*n:i*n+n]+c[i*n:i*n+n-N%2][::-1]for i in r(n)];return R+R[::-1][N%2:]


                                                    ungolfing a bit:



                                                    from random import * # get 'choice' and 'shuffle'
                                                    def matrix(N):
                                                    n = ceil(N/2) # get the size of the base block
                                                    # get a shuffleable lowercase alphabet
                                                    c = [chr(i+97)for i in range(26)]
                                                    c = n*c # make it large enough to fill the base-block
                                                    shuffle(c) # randomize it
                                                    digit = choice('1234567890') # get random digit string
                                                    ## this is only needed as to prevent uneven side-length matrices
                                                    # from having centerline digits.
                                                    allowed_indices = [i for i in range( # get all allowed indices
                                                    n*(N-n)) # skip those, that are in an unmirrored center-line
                                                    if(i+1)%n # only use those that are not in the center column
                                                    +1-N%2] # exept if there is no center column
                                                    index = choice(allowed_indices) # get random index
                                                    c[index]=digit # replace one field at random with a random digit
                                                    ##
                                                    R=
                                                    for i in range(n):
                                                    r = c[i*n:i*n+n] # chop to chunks sized fit for the base block
                                                    R.append(r+r[::-1][N%2:]) # mirror skipping the center line
                                                    return R+R[::-1][N%2:] # mirror skipping the center line and return


                                                    Older, almost correct versions below:



                                                    Python2, Python3, 161 bytes



                                                    from random import *
                                                    N=26
                                                    n=N-N//2
                                                    c=[chr(i+97)for i in range(26)]
                                                    R=[ r+r[::-1][N%2:]for r in[(shuffle(c),c[:n])[1]for i in range(n)]]
                                                    R+=R[::-1][N%2:]
                                                    print(R)


                                                    It seems N differing elements is only almost guarranteed.



                                                    Python 2/Python 3, 170 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;c=n*[chr(i+97)for i in r(26)][:n*n];shuffle(c);R=[_+_[::-1][N%2:]for _ in[c[i*n:i*n+n]for i in r(n)]];return R+R[::-1][N%2:]


                                                    It seems I forgot rule 3. Also somehow the [:n*n] slipped in.






                                                    share|improve this answer














                                                    Python 2/Python 3, 227 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;C=choice;c=n*[chr(i+97)for i in r(26)];shuffle(c);c[C([i for i in r(n*(N-n))if(i+1)%n+1-N%2])]=`C(r(10))`;R=[c[i*n:i*n+n]+c[i*n:i*n+n-N%2][::-1]for i in r(n)];return R+R[::-1][N%2:]


                                                    ungolfing a bit:



                                                    from random import * # get 'choice' and 'shuffle'
                                                    def matrix(N):
                                                    n = ceil(N/2) # get the size of the base block
                                                    # get a shuffleable lowercase alphabet
                                                    c = [chr(i+97)for i in range(26)]
                                                    c = n*c # make it large enough to fill the base-block
                                                    shuffle(c) # randomize it
                                                    digit = choice('1234567890') # get random digit string
                                                    ## this is only needed as to prevent uneven side-length matrices
                                                    # from having centerline digits.
                                                    allowed_indices = [i for i in range( # get all allowed indices
                                                    n*(N-n)) # skip those, that are in an unmirrored center-line
                                                    if(i+1)%n # only use those that are not in the center column
                                                    +1-N%2] # exept if there is no center column
                                                    index = choice(allowed_indices) # get random index
                                                    c[index]=digit # replace one field at random with a random digit
                                                    ##
                                                    R=
                                                    for i in range(n):
                                                    r = c[i*n:i*n+n] # chop to chunks sized fit for the base block
                                                    R.append(r+r[::-1][N%2:]) # mirror skipping the center line
                                                    return R+R[::-1][N%2:] # mirror skipping the center line and return


                                                    Older, almost correct versions below:



                                                    Python2, Python3, 161 bytes



                                                    from random import *
                                                    N=26
                                                    n=N-N//2
                                                    c=[chr(i+97)for i in range(26)]
                                                    R=[ r+r[::-1][N%2:]for r in[(shuffle(c),c[:n])[1]for i in range(n)]]
                                                    R+=R[::-1][N%2:]
                                                    print(R)


                                                    It seems N differing elements is only almost guarranteed.



                                                    Python 2/Python 3, 170 bytes



                                                    from random import*
                                                    def m(N):n=N-N//2;r=range;c=n*[chr(i+97)for i in r(26)][:n*n];shuffle(c);R=[_+_[::-1][N%2:]for _ in[c[i*n:i*n+n]for i in r(n)]];return R+R[::-1][N%2:]


                                                    It seems I forgot rule 3. Also somehow the [:n*n] slipped in.







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Sep 3 at 16:57

























                                                    answered Aug 31 at 22:38









                                                    Teck-freak

                                                    1314




                                                    1314











                                                    • Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                      – Chas Brown
                                                      Sep 2 at 22:30










                                                    • Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                      – Teck-freak
                                                      Sep 3 at 0:57










                                                    • Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                      – Chas Brown
                                                      Sep 3 at 5:01











                                                    • I litterally ran it over 10000 times without any error.
                                                      – Teck-freak
                                                      Sep 3 at 15:06










                                                    • found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                      – Teck-freak
                                                      Sep 3 at 15:11
















                                                    • Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                      – Chas Brown
                                                      Sep 2 at 22:30










                                                    • Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                      – Teck-freak
                                                      Sep 3 at 0:57










                                                    • Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                      – Chas Brown
                                                      Sep 3 at 5:01











                                                    • I litterally ran it over 10000 times without any error.
                                                      – Teck-freak
                                                      Sep 3 at 15:06










                                                    • found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                      – Teck-freak
                                                      Sep 3 at 15:11















                                                    Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                    – Chas Brown
                                                    Sep 2 at 22:30




                                                    Your answer is very clever in the way it constructs the symmetric matrix, but you have not satisfied rule 3 (as you don't have any digits in your result), nor rule 5 (e.g., if n = 3, you will never have an output containing a 'z', so not every output is possible).
                                                    – Chas Brown
                                                    Sep 2 at 22:30












                                                    Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                    – Teck-freak
                                                    Sep 3 at 0:57




                                                    Well pickle me and ... you're correct @ChasBrown ! Well, the [:n*n] is a remainder from a different approach and frankly it shouldn't be there. But you're correct about rule three. I'll have to correct it. Give me a bit.
                                                    – Teck-freak
                                                    Sep 3 at 0:57












                                                    Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                    – Chas Brown
                                                    Sep 3 at 5:01





                                                    Tried your solution here, but there was an index error... BTW, TryItOnline is super handy here at PPCG! (Also, this problem is way trickier than I thought at first...)
                                                    – Chas Brown
                                                    Sep 3 at 5:01













                                                    I litterally ran it over 10000 times without any error.
                                                    – Teck-freak
                                                    Sep 3 at 15:06




                                                    I litterally ran it over 10000 times without any error.
                                                    – Teck-freak
                                                    Sep 3 at 15:06












                                                    found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                    – Teck-freak
                                                    Sep 3 at 15:11




                                                    found it. a ':' was missing. I copied it directly from my script, but it must have gotten lost. it should be "... :-1][N%2:]for i ..." instead of "... :-1][N%2]for i ...".
                                                    – Teck-freak
                                                    Sep 3 at 15:11

















                                                     

                                                    draft saved


                                                    draft discarded















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f171435%2fsquare-random-symmetrical%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest













































































                                                    Comments

                                                    Popular posts from this blog

                                                    What does second last employer means? [closed]

                                                    Installing NextGIS Connect into QGIS 3?

                                                    One-line joke