Quick actions

cmd+k|ctrl+k

Navigation

Languages

Número Aleatórioa em Javascript

Snippet info

Language

JavaScript

Visibility

public

Author

elenderg

Created

2016-05-02T09:28:31Z

Updated

2016-05-02T09:28:31Z

function getRandomNumber (min, max, fixed) {
    var num = 0;

    if (min > max) {
        return ( -1 );
    }
    if (min == max) {
        return ( min );
    }

    if (fixed !== 0)
        num = parseFloat(min + (Math.random() * (max - min))).toFixed(fixed);
    else
        num = parseInt(min + (Math.random() * (max - min)));

    return num;
}

console.log(getRandomNumber(1,60));
console.log(getRandomNumber(1,60));
console.log(getRandomNumber(1,60));
console.log(getRandomNumber(1,60));
console.log(getRandomNumber(1,60));
console.log(getRandomNumber(1,60));
INFO