Generate multiple random numbers

Hi, I’m trying to figure out how to generate random numbers using Nightbot a certain amount of times based off the number put in after the command.

What I want to type:
!d20 4

What I want it to do:
Generate 4 random numbers between 1 and 20

I’ve scoured the internet and have not quite found what I need. I currently use the following code for generating a random number between 1 and 20:
$(eval Math.floor((Math.random() * 20) + 1))

I’d like to be able to generate more than one number, separated by commas, while using only one command

Hey @aubrynmusic!

You can do it like so:

$(eval r = () => Math.floor(Math.random() * 20) + 1; a = parseInt(`$(1)`); !isNaN(a) ? n = a : n = 1; [...Array(n)].map(() => r()).join(', ');)
1 Like

OMG thank you so much! You just saved me so much time and frustration! It works perfectly!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.