Comments on Roll n fair dice
Parent
Roll n fair dice
Challenge
This is a simple randomness challenge: Given a non-negative integer $n$, and positive integer $m$, simulate rolling and summing the results of $n$ fair dice, each of which have $m$ sides numbered $1$ through $m$.
Here is a basic ungolfed example in Python:
from random import randint
def roll(n, m):
return sum([randint(1, m) for i in range(n)])
Try it online! (Also includes a basic visualization of the resulting distribution)
This is code golf, so shortest code wins!
[Python 3], 61 bytes …
3y ago
[Ruby], 28 bytes -> …
2y ago
Dyalog APL, 2 bytes ```apl …
1y ago
[Python 3], 59 bytes …
2y ago
[C (gcc)], 48 43 bytes …
2y ago
J, 10 7 bytes ```J +/>:?#/ …
2y ago
Ruby, 27 24 bytes ->n,m{ …
3y ago
Japt `-mx`, 3 bytes Takes ` …
3y ago
Vyxal `ṪR`, 3 bytes ``` (⁰ …
3y ago
[Jelly], 4 bytes X}€S …
3y ago
Post
J, 10 7 bytes
+/>:?#/
+/>:?#/
#/ : Inserts dyadic # into an array n m
Creates n copies of m
? : Roll from 0..y
>: : Increment
+/ : Sum reduce
-3 bytes thanks to torres.
0 comment threads