| Bytes | Lang | Time | Link |
|---|---|---|---|
| 144 | Charcoal | 241014T011634Z | Neil |
| 262 | JavaScript Node.js | 241014T093144Z | l4m2 |
| 438 | Python 3.8 prerelease | 241013T231558Z | squarero |
| 165 | 05AB1E | 241014T141628Z | Kevin Cr |
| 376 | JavaScript ES6 | 241014T014739Z | Arnauld |
Charcoal, 146 144 bytes
≔⪪⪪”{∨8⬤⪫η÷﹪H⁵]”³¦³υF⪪⁺⁺×‽²⮌⭆⁶ι×⊗‽³⭆⁶⊕ι×‽⁴034215⁶UMυE³⮌⭆§υ§ιλ§ξμ¹¹P↗⁴↓:↓⁵↗'↗³↑:↑⁵←.←¹¹↙.↙³↓:↓⁵:¹¹J²±¹F§υ⁰«P↗ιM⁴→»J¹¦¹E§υ²⟦⪫ι ⟧J¹⁴±²F§υ⁴«P↓⪫ι ↙
Try it online! Link is to verbose version of code. Explanation:
≔⪪⪪”...”³¦³υ
Split a compressed string into six die faces.
F⪪⁺⁺×‽²⮌⭆⁶ι×⊗‽³⭆⁶⊕ι×‽⁴034215⁶
Create a series of permutations, consisting of a ½ chance of rotating the die so that the 123 and 546 faces switch places (this is equivalent to three 90° rotations), a ⅓ chance each of rotating the die around the 123-456 long axis by multiples of 120° (which is achieved by repeating a permutation to make the face rotations cancel out), and a ¼ chance each of rotating the die around the top-bottom axis by multiples of 90° (the top and bottom faces also have to be rotated in place, of course). For each permutation...
UMυE³⮌⭆§υ§ιλ§ξμ
... apply the permutation, rotating each face for each permutation.
¹¹P↗⁴↓:↓⁵↗'↗³↑:↑⁵←.←¹¹↙.↙³↓:↓⁵:¹¹
Draw the outline of the die.
J²±¹F§υ⁰«P↗ιM⁴→»
Draw the top face.
J¹¦¹E§υ²⟦⪫ι ⟧
Draw the front face.
J¹⁴±²F§υ⁴«P↓⪫ι ↙
Draw the right-hand face.
JavaScript (Node.js), 315 262 bytes
_=>`G .0.
G/1 3 2/|
/F 4 F/c|
/2 3 1/d |
:0:b a|
|7 5 6|E|
|GGG |a b:
|8 9 8| d/
|GGG |c/
|6 5 7|/
'0'`.replace(/\w/g,c=>c<1?'-----------':(u=c<{}?' ':'')+' o'[1&R>>('0xf'+c-5*e)%15]+u,R=[8724,18966,6864,1232,7218,6414,14998,6390][e=Math.random()*24|0,e%8])
Assume Arnauld's solution is correct as I geneated using its output
Python 3.8 (pre-release), 538 478 459 441 440 438 bytes
-60 bytes by compressing some strings of characters in the die string.
-18 bytes by emanresu A.
-1 more byte by reducing 2*(c>3) to c//4*2.
-18 bytes by using not-quite-bytestrings-but-close-enough.
-1 byte by eliminating the need for the %12.
-2 bytes by using actual bytestrings and reemploying the %12.
from random import*
R=randrange
S=str.replace
P=lambda s:f'{ord("(TŅŕŭđŅŕLJ"[n[s]%12]):09b}'.translate(' o'*50)
c=R(8)
n=[3,*b''[c%4:][:2],2+c%2*6][::1-c//4*2]
for _ in[0]*R(3):n[1:]=[n[3]+6,n[1]+6,n[2]]
print(((S(S(S(""" .B.
/A/|
/A/}{|
/A/}{ |
:B:}{ }{|
|A| }{ |
C }{:
|A| }{/
C/
|A|/
'B'""",'A',' %s %s %s '),'B','-'*11),'C','|'+' '*11+'|}{')%(*P(3)+P(1),))[::-1].format(*(a:=P(2))[6:]+a[3:6]+a[:3]))[::-1])
I've been banging my head against this problem for about 2 hours now (new record!). Thankfully, the byte count has gone down 100 bytes from the original submission.
...Is that a good thing?
05AB1E, 165 bytes
•1p6¼ujθ²
Ƶ@TV“α½[ÿ™ÆÅ´?µ¼…ǝÆ2.˜ã™Ā"ê7‰Ć₂1ƵcÕ н5Å₅ð¨ôÚ•" 4|
130/:2'."ÅвJ2'-11×:4ð3×:Ž£F0š0δšTΩiR}3LΩFÀÀ}4LΩFDŽBñS©èÁ®ǝεć4LNå+š]ε`•ʒ\RN]–ä•„o Åв3ô3ôsèsFøí]Ƶ2S©è€˜®s.;
Inspired by @Neil's Charcoal answer, so make sure to upvote that answer as well!
Explanation:
Step 1: Create the ASCII-art die, with placeholders for the nine positions of the random values:
•1p6¼ujθ²\nƵ@TV“α½[ÿ™ÆÅ´?µ¼…ǝÆ2.˜ã™Ā"ê7‰Ć₂1ƵcÕ н5Å₅ð¨ôÚ•
"# Push compressed integer 165694505690730716563168121971474439450718220748920420519623075258410088668853618104539042325788146223319708232484170071664982
" 4|\n130/:2'."Åв # Convert the large integer to base-" 4|\n130/:2'.",
# aka, convert it to base-12, and index into this string
J # Join all characters together
2'-11×: '# Replace all "2"s with a string consisting of 11 "-"s
4ð3×: # Replace all "4"s with a string consisting of 3 spaces
Step 2a: Create the default representation of the die:
Ž£F # Push compressed integer 41325
0š # Convert it to a list of digits, and prepend a 0
δ # Map over each digit:
0 š # Pair it with a leading 0
The leading 0s are the rotation-state, indicating how many times we'll have to rotate the face in step 3. The values [0,5] are the indices of the die-faces [1,6].
Step 2b,c,d: Just like @Neil's Charcoal answer, \$\frac{1}{2}\$ chance of inverting the die (aka reversing the representation of the die); then \$\frac{1}{3}\$ chance of rotating the die 120 degrees around a corner (aka rotating the representation of the dice twice counterclockwise); and then \$\frac{1}{4}\$ chance of rotating the die 90 degrees around a face (aka rotating the representation of the die at the 0-based indices 3→0→4→5→3, and simultaneously increasing the rotation-state at the 0-based indices 1,2,3,4 each once clockwise):
T # Push 10
Ω # Pop and push a random digit of it
i # If it's 1:
R # Reverse the list
} # Close the if-statement
3L # Push list [1,2,3]
Ω # Pop and push a random digit of it
F # Loop that many times:
ÀÀ # Rotate the list twice counter-clockwise
} # Close the loop
4LΩF # Similar again, looping randomly [1,2,3,4] amount of times:
D # Duplicate the current list
ŽBñ # Push compressed integer 3045
S # Convert it to a list of digits: [3,0,4,5]
© # Store it in variable `®` (without popping)
è # Get the current value-states at those 0-based indices
Á # Rotate them once clockwise
® # Push indices [3,0,4,5] again
ǝ # Insert the rotated value-states back into the list at those indices
ε # Map over each value-state pair:
ć # Extract head (the current rotation-state)
4L # Push list [1,2,3,4]
Nå # Check if the current 0-based map-index is in this list
# (1 if the index is 1/2/3/4; 0 if the index is 0/5)
+ # Add that check to the rotation-state
š # And prepend it back to the pair
] # Close both the inner map and outer loop
Step 3: Convert this representation of the die to actual die-values of spaces and "o":
ε # Map over each value-state:
` # Pop and push both values separated to the stack
•ʒ\RN]–ä• # Push compressed integer 17448688417330322
„o Åв # Convert it to base-"o "
3ô # Split it into triplets
3ô # And then split this list of triplets into 3x3 blocks
sè # Index the current face-index into this list of 3x3 blocks
sF # Loop the rotation-state amount of times:
øí # Rotate the 3x3 block once clockwise:
ø # Zip/transpose; swapping rows/columns
í # Reverse each inner row
] # Close the inner loop and outer map
Try just steps 2 and 3 online.
Step 4: Replace the placeholder digits in the ASCII-art die of step 1 with these random and correctly oriented/rotated die-faces:
Ƶ2 # Push random integer 103
S # Convert it to a list of digits: [1,0,3]
© # Store it in variable `®` (without popping)
è # Get the die-faces at those 0-based indices
€˜ # Flatten each 3x3 block to a list of 9 characters
® # Push the digits [1,0,3] again
s.; # Replace every "1", "0", and "3" one by one with its 9 face-characters in the ASCII-art die string
# (after which the result is output implicitly)
See this 05AB1E tip of mine to understand how the base of the ASCII-art is generated.
See this 05AB1E tip of mine (section How to compress large integers?) to understand why •1p6¼ujθ²\nƵ@TV“α½[ÿ™ÆÅ´?µ¼…ǝÆ2.˜ã™Ā"ê7‰Ć₂1ƵcÕ н5Å₅ð¨ôÚ• is 165694505690730716563168121971474439450718220748920420519623075258410088668853618104539042325788146223319708232484170071664982; ŽBñ is 3045; and •ʒ\RN]–ä• is 17448688417330322.
JavaScript (ES6), 376 bytes
-2 thanks to @l4m2
_=>[..._+""].reduce((p,_,c)=>(q=p.split(c)).join(q.pop(n=parseInt("0d6s2o0vn9uo33hkf42s3hnk3wawr4298ves0bjvf4378gw42t9h5u068so81efteq35ft0o33ndze301xqi141wy20bmphm01n4162ogucq467q222s0j6y33937y0lfd5m0dfc0e32bgey".substr((Math.random()*24|0)*6,6),36))),`0.2.
61|
1o|
1o |
:2:o3|43 |53:43/5/4/
'2'836o6o 7-----0 5
|660 |o4
|8|3 o277-1/8/06 `).replace(/o/g,c=>(n/=2)&1?c:" ")