Registry / http-networking / node-red-node-random

node-red-node-random

JSON →
library0.4.1jsnpmunverified

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-random
INSTALL
IMPORT
SIG · NODE-RED-NODE-RAND
N
node-red-node-random
http-networkingjavascriptv0.4.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Random node (from palette)
Install via Node-RED Palette Manager or `npm install node-red-node-random` in your user directory (~/.node-red), then drag the 'Random' node from the palette into a flow.
import { Random } from 'node-red-node-random'; // Node-RED nodes are not directly imported into user JavaScript files.
Node-RED nodes are installed as npm packages but are loaded by the Node-RED runtime, not imported into user-written JavaScript functions in the traditional sense. Functionality is accessed by wiring nodes in a flow.
Node-RED Flow JSON
{ "id": "<node-id>", "type": "random", "name": "My Random Number", "low": "0", "high": "100", "integers": "true" }
const randomNode = new RandomNode(); // Node definitions are internal to Node-RED; users interact with instances in flows.
When sharing Node-RED logic, the primary 'import' mechanism is exporting and importing flow JSON, which describes the nodes and their configurations.

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`.

[{"id":"d90d8a28.66d5b","type":"inject","z":"a8b2c3d4e5f6g7h8","name":"Trigger Random Number","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":100,"wires":[["e8f9a0b1.c2d3e4f5"]]},{"id":"e8f9a0b1.c2d3e4f5","type":"random","z":"a8b2c3d4e5f6g7h8","name":"Random Integer (1-10)","low":"1","high":"10","integers":"true","property":"payload","x":440,"y":100,"wires":[["f9a0b1c2.d3e4f5a6"]]},{"id":"f9a0b1c2.d3e4f5a6","type":"debug","z":"a8b2c3d4e5f6g7h8","name":"Output Debug","active":true,"toside":"true","console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":100,"wires":[]},{"id":"1b2c3d4e.5f6a7b8c","type":"inject","z":"a8b2c3d4e5f6g7h8","name":"Trigger Dynamic Float (0-1)","props":[{"p":"from","v":"0","vt":"num"},{"p":"to","v":"1","vt":"num"},{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":160,"wires":[["2c3d4e5f.6a7b8c9d"]]},{"id":"2c3d4e5f.6a7b8c9d","type":"random","z":"a8b2c3d4e5f6g7h8","name":"Random Float (dynamic)","low":"0","high":"100","integers":"false","property":"payload","x":440,"y":160,"wires":[["3d4e5f6a.7b8c9d0e"]]},{"id":"3d4e5f6a.7b8c9d0e","type":"debug","z":"a8b2c3d4e5f6g7h8","name":"Output Debug Dynamic","active":true,"toside":"true","console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":700,"y":160,"wires":[]}]
Debug
Known issues
gotchaWhen configured for integers, the random range is inclusive of both minimum and maximum values (`min <= n <= max`). For floating-point numbers, the range is inclusive of the minimum but exclusive of the maximum (`min <= n < max`). This difference can lead to off-by-one errors or unexpected results if not accounted for.
fix
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.
affects: >=0.1.0
gotchaValues configured directly in the 'Random' node's editor (hardcoded) will always take precedence over `msg.from` or `msg.to` properties passed in the incoming message. This can be misleading if a user expects message properties to dynamically override static settings.
fix
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**'.
affects: >=0.1.0
gotchaNode-RED nodes often update their behavior or dependencies. Because `node-red-node-random` is part of a larger `node-red-nodes` repository, detailed changelogs for individual nodes may not be readily apparent in their npm package, potentially obscuring breaking changes or new features introduced in `Milestone Releases` (e.g., v0.5.0, v0.6.0, v0.7.0, v0.8.0).
fix
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.
affects: >=0.4.0
Errors
Common errors & fixes
Node not found in palette after installation.
The Node-RED runtime might not have been restarted, or the node was installed in the wrong directory or failed installation.
fix
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.
Random number is outside expected range (e.g., maximum value is never reached for floats).
Misunderstanding of inclusive vs. exclusive range behavior for integer vs. floating-point number generation.
fix
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).
msg.from or msg.to values are ignored; the node always uses its configured static range.
Hardcoded 'From' and 'To' values in the node's configuration dialog take precedence over incoming `msg.from` and `msg.to` properties.
fix
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.
Upgrade
Version history
0.4.1latest on npm
Audit
Dependencies
node-redrequiredThis is a Node-RED node and requires a Node-RED runtime to function.
Agent activity
5 hits · last 30 days
node
4
Amazon
1
Resources
node-red-node-random — npm install node-red-node-random · libregistry