Hi,
I want my program to generate random numbers between -20 and +20 so how should I modify the following line ?
var randNum=Math.floor(Math.random()*???)
thanks for your help
Printable View
Hi,
I want my program to generate random numbers between -20 and +20 so how should I modify the following line ?
var randNum=Math.floor(Math.random()*???)
thanks for your help
I think all languages actually generate random numbers from 0 to the specified number (or one less than that, whatever). So you can generate a number out of 40, then subtract 20 from it.
VB Code:
var num = Math.floor(Math.random()*40)-20;
Which generates the closed interval [-20;19], i.e. including those two. If you want to include 20, too, you're generating 41 numbers and must adjust.