forked from node-red/node-red-nodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
random.js
24 lines (23 loc) · 816 Bytes
/
random.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
this.property = n.property||"payload";
var node = this;
this.on("input", function(msg) {
var value;
if (node.inte == "true" || node.inte === true) {
value = Math.round(Math.random() * (node.high - node.low + 1) + node.low - 0.5);
}
else {
value = Math.random() * (node.high - node.low) + node.low;
}
RED.util.setMessageProperty(msg,node.property,value);
node.send(msg);
});
}
RED.nodes.registerType("random",RandomNode);
}