China Naming Network - Ziwei Dou Shu - An ID in html calls JS to randomly generate numbers in the range of 200-2 10. Do you want to change it to 500-550?

An ID in html calls JS to randomly generate numbers in the range of 200-2 10. Do you want to change it to 500-550?

Generating random integers by JS is actually the application of Math.random (). Math.random () has a value range of [0, 1], so the code of a random integer with a value range of [500-550] is implemented as follows:

var num = 60 * math . random()+500;

Num is a random integer in the range of [500-550]. You can look at the blog garden article of the barrage monkey, which introduces the integer solution method in random range in detail.