Files
30-seconds-of-code/snippets/randomNumberInRange.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

439 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
randomNumberInRange math,random,beginner 2017-12-17T17:55:51+02:00 2020-10-22T20:24:04+03:00

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