Skip to content

Commit 584590b

Browse files
author
Dave Conway-Jones
committed
Fix random node to handle to or from being 0
and add tests to close #955
1 parent 5aa99ec commit 584590b

File tree

3 files changed

+169
-131
lines changed

3 files changed

+169
-131
lines changed

function/random/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "node-red-node-random",
3-
"version" : "0.4.0",
3+
"version" : "0.4.1",
44
"description" : "A Node-RED node that when triggered generates a random number between two values.",
55
"dependencies" : {
66
},

function/random/random.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ module.exports = function(RED) {
1818
if (node.low) { // if the the node has a value use it
1919
tmp.low = Number(node.low);
2020
} else if ('from' in msg) { // else see if a 'from' is in the msg
21-
if (Number(msg.from)) { // if it is, and is a number, use it
22-
tmp.low = Number(msg.from);
23-
} else { // otherwise setup NaN error
21+
tmp.low = Number(msg.from);
22+
if (isNaN(msg.from)) { // if it isn't a number setup NaN error
2423
tmp.low = NaN;
2524
tmp.low_e = " From: " + msg.from; // setup to show bad incoming msg.from
2625
}
@@ -31,9 +30,8 @@ module.exports = function(RED) {
3130
if (node.high) { // if the the node has a value use it
3231
tmp.high = Number(node.high);
3332
} else if ('to' in msg) { // else see if a 'to' is in the msg
34-
if (Number(msg.to)) { // if it is, and is a number, use it
35-
tmp.high = Number(msg.to);
36-
} else { // otherwise setup NaN error
33+
tmp.high = Number(msg.to);
34+
if (isNaN(msg.to)) { // if it isn't a number setup NaN error
3735
tmp.high = NaN
3836
tmp.high_e = " To: " + msg.to // setup to show bad incoming msg.to
3937
}

0 commit comments

Comments
 (0)