Ly, 29 26 bytes
'#o6['0'??'9G[p'(+,0]po,]p
Try it online!
At a high level, here's how this one works...
- write out
#
- loop 6 times...
- each iteration, write out a random digit in
0-f
range
And for people who like gory details about stacks. :)
'#o6['0'??'9G[p'(+,0]po,]p
'#o - push "#" on stack, print it as char
6[ ,] - loop 6 times
'0'? - push "0" and "?" codepoints on stack
? - pick a random number between them
'9G - is it greater then "9" codepoint?
[p 0]p - if/then, called if pick is > "9"
'( - push 28 on stack (Note 1)
+ - add 28 to random pick (Note 1)
, - decrement (Note 1)
o - print top of stack as a char
p - clear the loop artifact from the stack
Note 1: Mapping the codepoints :-?
to a-f
means adding 27 to the codepoint. The shortest way to do that would be to push '
onto the stack, but the code for that (at least on TIO) ''
doesn't work. So this code loads 28 (which is (
then decrements the result with ,
instead.
+
after the'#'
\$\endgroup\$#'+(Math.random()*0xffffff|0).toString(16)
\$\endgroup\$Math.random().toString(16)
can produce a representation with less than 6 hex-digits after the (hexa)decimal point, in which case the function would break. For example, 0.1658172607421875 becomes 0.2A73 in hex. \$\endgroup\$