Home › Forums › JavaScript › Your best snippets › Reply To: Your best snippets
December 6, 2016 at 3:47 pm
#248731
bearhead
Participant
Return a number 1-n with javascript:
number = Math.floor((Math.random() * n) + 1);
n can be any number, so if you wanted to simulate a 6-sided die roll, it would be a 6.
Pretty basic, but I use it all the time.