You need to give an object to the function:
faker.datatype.number({
'min': 10,
'max': 50
});
So if you just pass a number, it will set it as the max value. The min value is 0 by default.
This is the implementation of the number function :
this.number = function (options) {
if (typeof options === "number") {
options = {
max: options
};
}
options = options || {};
if (typeof options.min === "undefined") {
options.min = 0;
}
if (typeof options.max === "undefined") {
options.max = 99999;
}
if (typeof options.precision === "undefined") {
options.precision = 1;
}
// Make the range inclusive of the max value
var max = options.max;
if (max >= 0) {
max += options.precision;
}
var randomNumber = options.precision * Math.floor(
mersenne.rand(max / options.precision, options.min / options.precision));
return randomNumber;
}
Update
Latest versions changed location of the function from faker.random.number
to faker.datatype.number
, https://github.com/Marak/faker.js/issues/1156
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…