showing results for - "js roll function"
Selma
21 Jan 2016
1function roll(min, max, floatFlag) {
2    let r = Math.random() * (max - min) + min
3    return floatFlag ? r : Math.floor(r)
4}
5
6//example use case
7let userNames = ['James', 'Jane', 'Ryan', 'Rebecca']
8
9// Ages between 12 and 64
10
11// Heights between 5.1 and 6 meters
12
13let user = {
14    name: userNames[roll(0, userNames.length)],
15    age: roll(12, 65),
16    height: roll(5.1, 6.1, 1).toFixed(1)
17}
18console.log(user)