Skip to content
Advertisement

What would be a proper javascript code expression to this python code

How can I convert this code to javascript? I’ve tried different compilers, but none of them worked for me, guess I just couldn’t figure out how to use them

import random
randDuration = random.randint(1000, 2000)/1000

It’s a code generating random numbers between 1 and 2 with a thousandth fraction.

Advertisement

Answer

var randomnum = Math.floor(Math.random() * (2 * 1000 – 1 * 1000) + 1 * 1000) / (1*1000);

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement