I am trying to make a random number generator that can generate any number from 100 to 255. If anyone would be willing to explain/give that code, it would be very much appreciated. Thanks!
In particular, pay attention to Math.random(), which generates a random number between
You can then multiply this number to scale it up. For example,
Math.random() * 100 will generate a number between
To generate a number between
255, you could generate a random number between
155, then add
Other methods that might be helpful are:
- Math.round(), which rounds up or down to the nearest integer
- Math.floor(), which rounds down only
- Math.ceil(), which rounds up only
- Math.trun(), which removes any fractional digits (e.g: 1.23 becomes 1)
Good luck! Post your code here once you’re finished!