Pradeep Pandey
Pradeep Pandey

@Div_pradeep

5 Tweets 5 reads Jun 28, 2022
⚡How to Generate Random Number in a range in JavaScript?
A mini thread🧵👇🏻
→ We can generate random numbers in JavaScript using the `Math.random()` function.
→ But using this function you can only generate floating-point numbers between 0 and 1.
Example:
Getting numbers in a range:
→ But what if you wanted to return a random number between a range of your choice?
→ Say a whole number between 10 and 20?
→ Here's how you can do it.
→ Here multiplying the difference (20-10) by floatRandom gives you a random number between 0 and 10.
→ And adding the minimum number to this random value as seen in randomAboveMin gives you a random value between 10 and 20.
That's all for now.
I hope you found this thread helpful.
→ Please consider 💛 liking this tweet.
→ 🔁 Retweeting the first tweet so others can see it.
→ Follow ( @Div_pradeep) for more content.
Thank you for reading this thread.

Loading suggestions...