Use what you know: Your take on Diceware

-4

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.

Joseph

Posted 2016-01-07T04:11:03.837

Reputation: 135

Question was closed 2016-01-07T15:02:52.843

Like this? – x13 – 2016-01-07T13:00:59.510

@PeterTaylor - the question you marked this a duplicate of is not even close to the same. Please unmark the question as a duplicate. – Joseph – 2016-01-07T15:25:56.823

2It'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. – Peter Taylor – 2016-01-07T16:25:00.077

Answers

2

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.

Dennis

Posted 2016-01-07T04:11:03.837

Reputation: 196 637

1

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.

Alex A.

Posted 2016-01-07T04:11:03.837

Reputation: 23 761

1

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

grc

Posted 2016-01-07T04:11:03.837

Reputation: 18 565

0

TeaScript, 11 bytes

r6)ΣN6))j(u

Try it online

Downgoat

Posted 2016-01-07T04:11:03.837

Reputation: 27 116

0

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.

PurkkaKoodari

Posted 2016-01-07T04:11:03.837

Reputation: 16 699

0

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*

Martin Ender

Posted 2016-01-07T04:11:03.837

Reputation: 184 808

0

Mathematica, 36 bytes

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

cough cough string formatting cough cough

LegionMammal978

Posted 2016-01-07T04:11:03.837

Reputation: 15 731

0

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.

Stewie Griffin

Posted 2016-01-07T04:11:03.837

Reputation: 43 471