g | x | w | all
Bytes Lang Time Link
180BrainChild241120T004712ZATaco
151YASEPL240327T192916Zmadeforl
169Swift240304T191448ZmacOSist
343Assembly nasm240218T190239Zvengy
nanVyxal j240218T222544Zpacman25
034Uiua SBCS240215T221218Zchunes
nanWindows Batch Scripting240216T222327Zvengy
030APLDyalog Unicode240217T142628Zakamayu
111R240216T110644Zpajonk
03105AB1E240216T081551ZKevin Cr
037J240215T201953ZJonah
369Racket240216T155130ZMatthew
034APLDyalog Unicode240216T145617ZMukundan
124Python 3240216T042809Ztotallyh
022Jelly240215T210016ZJonathan
178Google Sheets240215T223339Zdoubleun
046APL+WIN240215T224857ZGraham
nanGoogle Sheets240216T044256Zz..
048Retina240215T230627ZNeil
030Charcoal240215T225630ZNeil
107JavaScript V8240215T210411ZArnauld
092Perl 5240215T222615ZXcali

BrainChild, 180 bytes

include *;int b=rand(256)var a=" @".chars;var p=putchar@int z=alloc(9)for(int x;int y<16;y++){for(x=0;x<16;x++)p(a[z[x]=rand(2)])p('|')for(x=0;x<16;x++)p(a[z[x]~(y*16+x)==b])p(10)}

Ungolfed & Explained

// Include required libs
include rand.bc;
include extmacros.bc;
include int.bc;
include string.bc;
// Select a bit to flip
int flippedbit = rand(256)
// An array of the chars ' ' and '@', this turned out to be the shortest way.
var a=" @".chars;
@int buff=alloc(9); // 9 isn't actually enough for a line, but as long as nothing else is allocated, this doesn't break (And could've been 0)
// For each line
// y isn't explicitely set to anything, because it defaults to 0 and is called once, but we use the for loops initializer to initialize x instead.
for(int x;int y<16;y++){
    // Print 16 random selections of the char array, setting the buffer as we go.
    for(x=0;x<16;x++){
        putchar(a[buff[x]=rand(2)])
    }
    putchar('|') // And the newline
    // Reprint the buffer
    for(x=0;x<16;x++){
        // XOR the buffer value with the check if this is the one to flip.
        putchar(a[buff[x]~(y*16+x)==flippedbit])
    }
    // Newlines.
    putchar('\n');
}

Try It Online!

YASEPL, 151 bytes

=v=a$64»=i£1=r¢0,255`1!s[3#pipe`3=j`2!s[7!o¥j,1!)o!g$16*i+j}7,r,9!)a!o}7,a,9!)" "`9!~|8`7!b)a!m¢0,1@6!b)" "`6!b~!1©b`8!j+}2,17,2!s@4$|`4=s£1>""!i+}2,17

Swift, 179 176 169 bytes

var r=0..<16,a=r.map{_ in r.map{_ in !(.random())}},s={""+($0+[]).map{$0 ?"@":" "}}
zip(a,(a[.random(in:r)][.random(in:r)].toggle(),a).1).map{print(s($0.0)+"|"+s($0.1))}

Assembly (nasm, x64, Linux), 343 bytes

mov byte[l+16],'|' 
mov byte[l+33],10 
rdrand ax
movzx r12,al
mov bl,0
mov r14,16
p:mov rcx,16
mov r9,l
r:rdrand r8
and r8,1
mov al,[c+r8]
mov[r9],al
cmp r12,rbx
jne o
cmp al,64
je s
add al,32
jmp o
s:sub al,32
o:mov[r9+17],al
inc r9
inc bl
loop r
mov rax,1
mov rdi,1
mov rsi,l
mov rdx,34
syscall
dec r14
jnz p
c db "@ "
section .bss
l resb 34

Try it online!

Notes

rdrand is an instruction for returning random numbers from an Intel on-chip hardware random number generator.

Set r12 to a random number \$[0,255]\$

rdrand ax
movzx r12,al

Set r8 to a random number \$[0,1]\$

rdrand r8
and r8,1

Vyxal j, 169 bitsv2, 21.125 bytes

₈ÞB:₈ṁ⁽¬V"ƛ‛ @i;ṅ²÷Zƛ\|j

Try it Online!

Bitstring:

1010111011001011000000101101001010011100010010011000001111001011010101011001000001000110000001100000001001100110111011001000100101001001111010100000110110101011110100100
₈ÞB:₈ṁ⁽¬V"ƛ‛ @i;ṅ²÷Zƛ\|j­⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁣‏⁠⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁡⁡‏⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁢⁡⁣‏⁠‎⁡⁠⁢⁡⁤‏‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏⁠‎⁡⁠⁢⁢⁤‏‏​⁡⁠⁡‌­
₈ÞB                       # ‎⁡256 random bits
   :₈ṁ⁽¬V                 # ‎⁢copy and flip a bit at a random index
         "                # ‎⁣pair them into a list
          ƛ    ;          # ‎⁤map over each
           ‛ @i           # ‎⁢⁡the corresponding index of the string " @" 
                ṅ²        # ‎⁢⁢concatenate, turn each string into a square
                  ÷Z      # ‎⁢⁣push each square and zip the two
                    ƛ\|j  # ‎⁢⁤join by |
💎

Created with the help of Luminespire.

decoder (not at all golfed)

Uiua SBCS, 36 35 34 bytes

⊏⍉⊂⊂:↥2⊢.⍜⊡¬⌊×16⊟⚂⚂.⁅⊞⋅⋅⚂.⊚16"@ |"

Try it!

⊏⍉⊂⊂:↥2⊢.⍜⊡¬⌊×16⊟⚂⚂.⁅⊞⋅⋅⚂.⊚16"@ |"
                             "@ |"  # push string
                    ⁅⊞⋅⋅⚂.⊚16       # 16x16 binary random matrix
                   .                # duplicate
         ⍜⊡¬⌊×16⊟⚂⚂                 # invert a random cell
   ⊂:↥2⊢.                           # append row of 2s
  ⊂                                 # prepend original matrix
 ⍉                                  # transpose
⊏                                   # convert to proper ascii symbols

Windows Batch Scripting, 469 262 259 bytes

Thanks to Neil's tips.

@echo off&setlocal EnableDelayedExpansion&set/av=%random%%%256
for /L %%i in (0,1,255)do (set/ar=!random!%%2&set c= &if !r!==0 set c=@
set a=!a!!c!&if %%i==%v% if !c!==@ (set c= )else set c=@
set b=!b!!c!&set/ae=%%i%%16&if !e!==15 echo !a!^|!b!&set a=&set b=)

Notes

EnableDelayedExpansion Delayed Expansion will cause variables within a batch file to be expanded at execution time rather than at parse time.

%random%%%256 generates a random number in the range \$[0,255]\$.

Output

out

APL(Dyalog Unicode), 30 bytes SBCS

Assume Index Origin is 0 (⎕IO←0)

' @|'[i,2,~@(⊂?⍴i)⊣i←?16 16⍴2]

Try it on aplgolf

⍝ Rough explaination

' @|'[i,2,~@(⊂?⍴i)⊣i←?16 16⍴2]
                   i←?16 16⍴2  ⍝ 1. i is a random 16 by 16 bit matrix
          ~@(⊂?⍴i)⊣i           ⍝ 2. i with one random bit toggled
      i,2,~@(⊂?⍴i)⊣i           ⍝ 3. Matrix of i, 2, and the toggled i
' @|'[                       ] ⍝ 4. Indexing into string ' @|'

⍝ Breakdown of step 2

          ~@(⊂?⍴i)⊣i
               ⍴i              ⍝ 2-1. The shape of i
              ?⍴i              ⍝ 2-2. A random index into i
          ~@(⊂?⍴i)             ⍝ 2-3. A function that toggles at the index
          ~@(⊂?⍴i)⊣i           ⍝ 2-4. i with one random bit toggled

ngn/k, 32 bytes

+" @|".[i;2?#i;~:],2,i:16?+!16#2

Try it online

R, 112 111 bytes

s=sample
A=B=s(2,256,T)
B[i]=3-B[i<-s(256,1)]
`?`=\(v)matrix(c("@"," ")[v],16)
cat(rbind(?A,"|",?B,"
"),sep="")

Attempt This Online!

05AB1E, 31 bytes

₁F„@ Ω}JÐ₅ÝΩ©è„@ ‡®ǝ‚16δôø'|ý»

Try it online.

Replaced the incorrect „@ ₁×.r₁£ with ₁F„@ ΩJ} (also -1 byte) to fix the issue mentioned by @Neil: "Strictly speaking, step 1 doesn't generate 256 independent characters; the chances for all @s is \$(256!)^2\$ in \$512!\$ instead of \$1\$ in \$2^{256}\$."

Explanation:

Step 1: Generate a random string of 256 "@" and " ", with a 50% chance each:

₁F           # Loop 256 times:
  „@         #  Push string "@ "
     Ω       #  Pop and push a random character from it
      }J     # After the loop: Join all characters on the stack together 

Try just step 1 online.

Step 2: Create a copy, and flip the character at a single random position:

Ð             # Triplicate the string
 ₅Ý           # Push a list in the range [0,255]
   Ω          # Pop and push a random integer from it
    ©         # Store this random index-integer in variable `®` (without popping)
     è        # Pop one of the strings, and get the character at this index
      „@      # Push string "@ " again
        Â     # Bifurcate it; short for Duplicate & Reverse copy
         ‡    # Transliterate "@" to " " and vice-versa
          ®ǝ  # Pop another string, and insert this flipped character at index `®`
            ‚ # Pair the two strings together

Try just the first two steps online.

Step 3: Format it correctly and output the result:

  δ           # Map over both strings in the pair:
16 ô          #  Split it into parts of size 16 each
    ø         # Zip/transpose; swapping rows/columns
     '|ý     '# Join each inner pair together with "|"-delimiter
        »     # Join the list of strings together by newlines
              # (which is output implicitly as result)

J, 41 38 37 bytes

' @|'{~(?@$&2([,.2,.~:)?|.{.&1)@16 16

Try it online!

-1 thanks to Mukundan314

Racket, 369 Bytes

(define(f x)(if(empty? x)x(cons(take x 16)(f(drop x 16)))))(let*([s list->string][b build-list][m map][g((λ(x)(list(m(λ(x y)(xor x y))x(b 256((λ(y)(λ(x)(= y x)))(random 256))))x))(b 256(λ(x)(=(random 2)0))))][h(λ(x)(m(λ(x)(if x #\@#\ ))x))][i(list(m s(f(h(car g))))(m s(f(h(cadr g)))))])(display(string-join(m(λ(x y)(string-append x"|"y))(car i)(cadr i))"\n")))

Try it online!

This is my first post here so I'm hoping I'm following all the rules. I'm also still learning Racket so I'm sure this isn't optimized and I'm excited to receive any tips, but I wanted to post as far as I've gotten. Below is a rough description of what's going on.

#lang racket
;splits a list of 256 into 16 lists of 16
(define(f x)(if(empty? x)x(cons(take x 16)(f(drop x 16)))))

(let*(
      ;shorten reused functions
      [s list->string]
      [b build-list]
      [m map]

      ;generate a pair of boolean lists of lists differing by 1 entry
      [g((λ(x)(list(m(λ(x y)(xor x y))x(b 256((λ(y)(λ(x)(= y x)))(random 256))))x))(b 256(λ(x)(=(random 2)0))))]

      ;convert #t and #f into #\@ and #\ 
      [h(λ(x)(m(λ(x)(if x #\@#\ ))x))]

      ;create list of strings from list of list of chars
      [i(list(m s(f(h(car g))))(m s(f(h(cadr g)))))])

  ;concat strings
  (display(string-join(m(λ(x y)(string-append x"|"y))(car i)(cadr i))"\n")))

APL(Dyalog Unicode), 34 bytes SBCS

Requires Index Origin 0 (⎕IO←0)

' @|'[A,2,A≠(⍴A←?16 16⍴2)⍴1=?⍨256]

Try it on APLgolf!

' @|'[A,2,A≠(⍴A←?16 16⍴2)⍴1=?⍨256]­⁡​‎‎⁡⁠⁢⁡⁢‏⁠‎⁡⁠⁢⁡⁣‏⁠‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏⁠‎⁡⁠⁢⁢⁤‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁤​‎‏​⁢⁠⁢‌⁢⁡​‎‎⁡⁠⁢⁤⁡‏⁠‎⁡⁠⁢⁤⁢‏⁠‎⁡⁠⁢⁤⁣‏⁠‎⁡⁠⁢⁤⁤‏⁠‎⁡⁠⁣⁡⁡‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁢⁣⁣‏⁠‎⁡⁠⁢⁣⁤‏‏​⁡⁠⁡‌⁢⁣​‎‎⁡⁠⁢⁣⁢‏‏​⁡⁠⁡‌⁢⁤​‎‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏‏​⁡⁠⁡‌⁣⁡​‎‎⁡⁠⁣⁣‏⁠‎⁡⁠⁣⁤‏‏​⁡⁠⁡‌⁣⁢​‎‎⁡⁠⁣⁡‏⁠‎⁡⁠⁣⁢‏‏​⁡⁠⁡‌⁣⁣​‎⁠‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏‏​⁡⁠⁡‌⁣⁤​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏⁠‎⁡⁠⁣⁡⁢‏‏​⁡⁠⁡‌­
                 16 16⍴2            # ‎⁡generate 16, 16 matrix of 2s
                ?                   # ‎⁢replace each with random number less than current value
              A←                    # ‎⁣assign to A
‎⁤
                            ?⍨256   # ‎⁢⁡random permutation of [0, 1, ..., 255]
                          1=        # ‎⁢⁢equals 1 (vectorized)
                         ⍴          # ‎⁢⁣reshape to
             ⍴A                     # ‎⁢⁤shape of A (16, 16)
          A≠                        # ‎⁣⁡not equal/xor against A (vectorized)
        2,                          # ‎⁣⁢concatenate column of 2 to start
      A,                            # ‎⁣⁣concatenate A to start
' @|'[                           ]  # ‎⁣⁤translate to required characters
💎

Created with the help of Luminespire.

Python 3, 147 141 139 138 124 bytes

-8 bytes thanks to Mukundan314. -14 bytes thanks to Jonathan Allan.

from random import*
g=getrandbits
n=g(4)
r=16
while r:r-=1;s=g(16);print(f'{s:16b}|{s^(r==n)<<g(4):16b}'.translate('@ '*25))

Try it online!

Explanation (outdated)

That's a lot of use out of Python's random module. First, it iterates over \$[0, 16)\$ shuffled with for r in sample(a:=range(16),16). The random ordering means that r will only be zero once, but it can be on any of the 16 iterations. When this is the case, the row that it outputs in that iteration will contain the difference.

It represents cells as bits and therefore, rows as 16-bit integers. Luckily, getrandbits(16) can generate a random 16-bit integer like 16846 or 01000001110011102. (Though randrange(65536) or randint(0,65535) would've worked just as well.)

Now, for the interesting bit manipulation. To toggle a random cell, it takes the bitwise XOR of the row with a 16-bit integer that has only one randomly chosen bit turned on like 00010000000000002. This integer can be made by left shifting 1 bitwise by a random integer in \$[0, 16)\$. When r is zero, r<1 is True, which can be used as if it were 1 in numerical operations. choice(a) returns a random choice from \$[0, 16)\$. Therefore, s^(r<1)<<choice(a) computes something like:

   00000000000000012
<<               12
-------------------- 
   00010000000000002
 ^ 01000001110011102
-------------------- 
   01010001110011102

However, when r is not zero, left shifting False or 0 bitwise or taking the bitwise XOR of it with something does nothing.

Finally, in order to represent it as a string and turn the bits into @s and spaces, it first uses a format string {s:16b}. This converts the integer into binary and pads it with enough spaces to increase its length to 16, turning 16846 into ' 100000111001110'. It then uses .translate({49:64,48:32}) (a table of the characters' respective ASCII ordinal numbers) to turn it into ' @ @@@ @@@ '.

Jelly,  25  22 bytes

⁹ḶẊ⁾ @Ẋḷ\⁹¡¥Ɱs⁴Z€j€”|Y

Try it online!

How?

⁹ḶẊ⁾ @Ẋḷ\⁹¡¥Ɱs⁴Z€j€”|Y - Link: no arguments
⁹                      - 256
 Ḷ                     - lowered range {256} -> [0..255]
  Ẋ                    - shuffle -> IsEqualIndicators
   ⁾ @                 - list of characters -> " @"
            Ɱ          - map across {i in IsEqualIndicators} with:
           ¥           -   last two links as a dyad - f(" @", i):
      Ẋ                -     shuffle {" @"} -> " @" or "@ "
         ⁹¡            -   repeat {i} times: (i.e. a no-op when i=0)
        \              -     cumulative reduce {ShuffledCharacters} by:
       ḷ               -       left argument
                            (first takes " @" to "  ", or "@ " to "@@"
                             then further applications have no more effect)
             s⁴        - split into chunks of 16
               Z€      - transpose each
                 j€”|  - join each with '|'
                     Y - join with newlines

Here is a difference spotter which accepts an output and replaces any space on one of the two sides where there is an @ on the other with a +.

Google Sheets, 178 bytes

=index(let(y,row(1:16),x,torow(y),t,(x=randbetween(1,16))*(y=randbetween(1,16)),g,map(t,lambda(_,if(coinflip()," ","@"))),{g,if(y,"|"),if(t,if(""=tocol(if(t,g,),1),"@"," "),g)}))

Put the formula in cell A1.

spotdiff.png

Ungolfed:

=arrayformula(let( 
  y, sequence(16), 
  x, transpose(y),
  truthyTable, (x = randbetween(1, 16)) * (y = randbetween(1, 16)), 
  firstGrid, map(truthyTable, lambda(_, if(coinflip(), "@", " "))), 
  currentChar, tocol(if(truthyTable, firstGrid, iferror(ø)), 1), 
  flipChar, if(" " = currentChar, "@", " "), 
  secondGrid, if(truthyTable, flipChar, firstGrid), 
  hstack(firstGrid, if(y, "|"), secondGrid) 
))

APL+WIN, 54 46 bytes

Index origin = 0

'@ |'[(2|z+m⍴(?i)⌽i↑1),2,z←(m←2⍴16)⍴2|i?i←256]

Try it online!Thanks to Dyalog Classic

Google Sheets, 170 161 bytes

Formula in \$A1\$

=INDEX(LET(g,MAP(A25:P40,LAMBDA(_,IF(COINFLIP(),"@"," "))),r,ROW(1:16),{g,IF(r,"|"),IF((r=RANDBETWEEN(1,16))*(TOROW(r)=RANDBETWEEN(1,16)),IF(g="@"," ","@"),g)}))

enter image description here

Retina, 49 48 bytes


16*$(16*$( @)¶
(.){2}
$?1
.+
$&|$&
@T` @`@ ` |@

Try it online! Edit: Saved 1 byte thanks to @Leo. Explanation:


16*$(16*$( @)¶

Insert a 16×16 grid of pairs of spaces and @s.

(.){2}
$?1

Pick a random character from each pair.

.+
$&|$&

Duplicate each row joined with |.

@T` @`@ ` |@

Flip a random space or @.

16-byte difference spotter written in Retina 0.8.2:

+`@(.{16})@
 $1 

Try it online! Removes all of the paired @s.

Charcoal, 30 bytes

↶≔¹⁶θEθ⭆θ‽ @C⊕θ⁰θJ‽θ±‽θ§ @⁼ KK

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

Change the default drawing direction to upwards.

≔¹⁶θ

Save the value 16 in a variable because it gets used to much.

Eθ⭆θ‽ @

Output a random 16×16 grid of spaces and @s.

C⊕θ⁰

Copy it 17 characters to the right.

θ

Draw a line of length 16 in the default drawing direction.

J‽θ±‽θ

Jump to a random position.

§ @⁼ KK

Toggle the character at that position.

JavaScript (V8), 107 bytes

A full program.

for(R=Math.random,v=R(n=16)*512|0;n--;print(s))for(k=33,m=R(s="")*2**k;k--;)s+=" @|"[k-16?m>>k%17&1^!v--:2]

Try it online!


C (gcc), 106 bytes

f(v,n,m,k){for(v=rand(n=16)&511;n--;)for(m=rand(k=33);~k--;)putchar(~k?k-16?32<<(m>>k%17&1^!v--):124:10);}

Try it online!

Perl 5, 92 bytes

@s=map{(@z=map{('@',$")[rand 2]}0..15),'|',@z,$/}0..15;$s[34*(0|rand 16)+rand 16]^='`';say@s

Try it online!