Files
30-seconds-of-code/snippets/randomNumberInRange.md
Isabelle Viktoria Maciohsek d35575373f Update snippet descriptions
2020-10-22 20:24:04 +03:00

363 B

title, tags
title tags
randomNumberInRange math,random,beginner

Generates a random number in the specified range.

  • Use Math.random() to generate a random value, map it to the desired range using multiplication.
const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
randomNumberInRange(2, 10); // 6.0211363285087005