1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/function/random/random.js

22 lines
708 B
JavaScript
Raw Normal View History

2014-10-27 21:26:49 +01:00
module.exports = function(RED) {
"use strict";
function RandomNode(n) {
RED.nodes.createNode(this,n);
this.low = Number(n.low || 1);
this.high = Number(n.high || 10);
this.inte = n.inte || false;
2014-10-27 21:26:49 +01:00
var node = this;
this.on("input", function(msg) {
if (node.inte == "true" || node.inte === true) {
2014-10-27 21:26:49 +01:00
msg.payload = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5);
2017-01-29 18:45:44 +01:00
}
else {
2014-10-27 21:26:49 +01:00
msg.payload = Number(Math.random()) * (node.high - node.low) + node.low;
}
node.send(msg);
});
}
RED.nodes.registerType("random",RandomNode);
}