davidbau / seedrandom

seeded random number generator for Javascript
2.06k stars 160 forks source link

geneare number between a range #26

Closed sonill closed 9 years ago

sonill commented 9 years ago

How can i use "seedrandom" to generate a random number between a specific range.

For example: generate number between "0" - "20". I do not want float numbers.

Thank you for any help.

davidbau commented 9 years ago

Just multiply by 20 and round yourself:

var rng = new Math.seedrandom(1);
console.log(Math.floor(rng() * 20))

Seedrandom does not include convenience methods for generating other types of random varibles. However, if you prefer to start with a 32-bit signed integer, you can always use rng.int32() and start from there.