Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a random number between 0.0200 and 0.120 (float numbers) [duplicate]

Tags:

javascript

I need to create a random number between 0.0200 and 0.120 using JavaScript. How would I do this?

like image 446
danieljames Avatar asked Jul 18 '13 14:07

danieljames


People also ask

How do I generate a random decimal number between two numbers in Excel?

1. Select a blank cell, and type =RAND() into it, and then drag the fill handle to fill the range you need with the formula. 2. Then select the range you have applied the formula, and click the Increase Decimal button or Decrease Decimal button under Home tab to specify the decimal numbers.

How can we generate a random float number between 1 and 10 in python?

Use a random. random() function of a random module to generate a random float number uniformly in the semi-open range [0.0, 1.0) . Note: A random() function can only provide float numbers between 0.1. to 1.0. Us uniform() method to generate a random float number between any two numbers.

How can you pick randomly a float between 0 and 1 in JS?

Math. random() as is will generate a random float number between 0.0 and 1.0 . From 0 inclusive to 1 exclusive.


1 Answers

You could use

(Math.random() * (0.120 - 0.0200) + 0.0200).toFixed(4) 

toFixed(n) is used to convert a number into a string, keeping only the "n" decimals.

Hope it helps ^_^

like image 71
Alesanco Avatar answered Sep 28 '22 21:09

Alesanco