# 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 …

5mo ago

[Ruby], 32 bytes ```ruby - …

5mo ago

Japt `-mx`, 3 bytes Takes ` …

5mo ago

Vyxal `ṪR`, 3 bytes ``` (⁰ …

5mo ago

[Jelly], 4 bytes X}€S …

5mo ago

Ruby, 27 bytes ```ruby ->n …

15d ago

## 6 answers

# Python 3, 61 bytes

```
lambda n,m:sum(randint(1,m)for i in[0]*n)
from random import*
```

This is not an interesting answer as it is just a copy of your code. I tried to do it with choices but it's 1 byte longer : Try it online!

#### 0 comment threads

#
Vyxal `ṪR`

, 3 bytes

```
(⁰℅
```

```
( # N times...
℅ # Generate a random integer between one and...
⁰ # First argument
```

#### 0 comment threads

# Jelly, 4 bytes

```
X}€S
```

## How it works

```
X}€S - Main link. Takes n on the left, m on the right
€ - Over each element of 1 through n:
} - With m as its argument:
X - Yield a random integer from 1 to m
S - Sum
```

## 0 comment threads