The `node-red-node-random` package provides a Node-RED node that generates random numbers based on configurable minimum and maximum values. It is a fundamental utility node for introducing variability into Node-RED flows, suitable for simulations, testing, or dynamic control systems. The node, currently at version 0.4.1 (though the GitHub repository indicates releases up to 0.8.0), is actively maintained by the Node-RED project. It allows for generating either integers within an inclusive range (`min <= n <= max`) or floating-point numbers within a range that is inclusive of the minimum but exclusive of the maximum (`min <= n < max`). A key differentiator is its ability to accept dynamic 'From' and 'To' values via `msg.from` and `msg.to` properties, although hardcoded node configurations take precedence. It's released as part of the `node-red-nodes` collection, which typically sees updates aligned with Node-RED core releases or as needed for individual nodes.
npm install node-red-node-randomVerified import paths — ran on the pinned version, not inferred.
This Node-RED flow demonstrates two uses of the Random node: generating a static random integer between 1 and 10, and generating a dynamic floating-point number between 0 and 1, overriding the node's hardcoded range using `msg.from` and `msg.to`.
Always review the node's configuration and the expected range behavior (inclusive/exclusive) for both integer and float outputs. Adjust `min` or `max` values accordingly to achieve the desired range.
To use dynamic `msg.from` and `msg.to` values, ensure that the 'From' and 'To' fields in the Node-RED editor for the Random node are left blank or configured in a way that allows the message properties to be effective (e.g., using a variable expression if the node supported it, but for this node, leaving them blank is the key). The README explicitly states 'hard coded values in the node **always take precedence**'.
Consult the main `node-red-nodes` GitHub repository's release notes or commit history for granular details on changes affecting specific nodes if unexpected behavior occurs after an update, especially across major Node-RED versions.
Ensure `npm install node-red-node-random` was run in your Node-RED user directory (typically `~/.node-red`). Restart Node-RED (`node-red-restart` or `pm2 restart node-red` etc.). Check Node-RED logs for installation errors.
Remember that integers include both `min` and `max` (`min <= n <= max`), while floats include `min` but exclude `max` (`min <= n < max`). Adjust your `high` value accordingly. For example, if you want floats up to 10.0 (inclusive), set `high` to 10.000001 (or just above 10).
To allow dynamic range setting via `msg.from` and `msg.to`, ensure the 'From' and 'To' fields within the 'Random' node's configuration in the Node-RED editor are left blank.