-4
\$\begingroup\$

This question already has an answer here:

If you're not familiar, Diceware is a method for creating passwords using an ordinary die from a pair of dice as a hardware random number generator.

For the sake of fun, let's ignore anything about the security of computer's random number generators.

Write a function or program that prints or returns a single five-character string containing a random selection of the numbers 1 through 6. These should be chosen with equal probability.

Example valid outputs:

21321
14654
53552
63641

No standard loopholes! This is code-golf, so shortest code in bytes wins.

\$\endgroup\$

marked as duplicate by Peter Taylor code-golf Jan 7 '16 at 15:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Like this? \$\endgroup\$ – x13 Jan 7 '16 at 13:00
  • \$\begingroup\$ @PeterTaylor - the question you marked this a duplicate of is not even close to the same. Please unmark the question as a duplicate. \$\endgroup\$ – Joseph Jan 7 '16 at 15:25
  • 2
    \$\begingroup\$ It's replacing an is-zero test with a loop. That's a trivial change, and by the standards of this site qualifies as a duplicate. \$\endgroup\$ – Peter Taylor Jan 7 '16 at 16:25
2
\$\begingroup\$

Dyalog APL, 7 bytes

10⊥?5⍴6

Try it online on TryAPL.

How it works

    5⍴6  Yield (6 6 6 6)
   ?     Roll; turn each 6 into a random integer between 1 and 6.
10⊥      Decode with base 10.
\$\endgroup\$
1
\$\begingroup\$

Julia, 24 bytes

print(join(rand(1:6,5)))

We use rand to get an array of length five consisting of elements randomly chosen from the range 1:6. We join it into a string using join then print it to STDOUT using print.

\$\endgroup\$
1
\$\begingroup\$

J, 11 bytes

a.{~49+?5$6

Explanation:

        5$6    NB. repeat 6 five times      output: 6 6 6 6 6
       ?5$6    NB. 5 random integers < 6    output: 4 5 1 0 2
    49+?5$6    NB. add 49 ('1') to them     output: 53 54 50 49 51
a.{~49+?5$6    NB. convert them to ASCII    output: 56213
\$\endgroup\$
0
\$\begingroup\$

Pyth, 9 8 bytes

jkO^S6 5

Try it online.

Get list of numbers 1 to 6, Cartesian 5th power, pick random element, join by empty string.

\$\endgroup\$
0
\$\begingroup\$

CJam, 8 bytes

{6mr)}5*

Test it here.

Explanation

{       e# Run this block 5 times.
   6mr  e# Get a random integer in [0,5] with uniform distribution.
   )    e# Increment.
}5*
\$\endgroup\$
0
\$\begingroup\$

Mathematica, 36 bytes

""<>ToString/@{1,6}~RandomInteger~5&

cough cough string formatting cough cough

\$\endgroup\$
0
\$\begingroup\$

MATLAB / Octave, 12 bytes

[49+6*rand(1,6),'']
ans = 153361

rand(x,y) creates a random array with dimensions (x-by-y) with numbers between 0 and 1. Multiply this by 6 to get values between 0 and 6. Add 49 to get a value 49 < n < 55 (the random number will never be exactly 0 or 1). [...,''] converts this to strings with the floored values of n (integers [49 54] corresponding to [1 6] in ASCII.

\$\endgroup\$
0
\$\begingroup\$

TeaScript, 11 bytes

r6)ΣN6))j(u

Try it online

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.