{"id":11446,"library":"node-red-node-random","title":"Node-RED Random Number Generator","description":"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.","status":"active","version":"0.4.1","language":"javascript","source_language":"en","source_url":"https://github.com/node-red/node-red-nodes","tags":["javascript","node-red","random"],"install":[{"cmd":"npm install node-red-node-random","lang":"bash","label":"npm"},{"cmd":"yarn add node-red-node-random","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-red-node-random","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Node-RED node and requires a Node-RED runtime to function.","package":"node-red","optional":false}],"imports":[{"note":"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.","wrong":"import { Random } from 'node-red-node-random'; // Node-RED nodes are not directly imported into user JavaScript files.","symbol":"Random node (from palette)","correct":"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."},{"note":"When sharing Node-RED logic, the primary 'import' mechanism is exporting and importing flow JSON, which describes the nodes and their configurations.","wrong":"const randomNode = new RandomNode(); // Node definitions are internal to Node-RED; users interact with instances in flows.","symbol":"Node-RED Flow JSON","correct":"{ \"id\": \"<node-id>\", \"type\": \"random\", \"name\": \"My Random Number\", \"low\": \"0\", \"high\": \"100\", \"integers\": \"true\" }"}],"quickstart":{"code":"[{\"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\":[]}]","lang":"json","description":"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`."},"warnings":[{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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**'.","message":"Values 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.","severity":"gotcha","affected_versions":">=0.1.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.","message":"Node-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).","severity":"gotcha","affected_versions":">=0.4.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"The Node-RED runtime might not have been restarted, or the node was installed in the wrong directory or failed installation.","error":"Node not found in palette after installation."},{"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).","cause":"Misunderstanding of inclusive vs. exclusive range behavior for integer vs. floating-point number generation.","error":"Random number is outside expected range (e.g., maximum value is never reached for floats)."},{"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.","cause":"Hardcoded 'From' and 'To' values in the node's configuration dialog take precedence over incoming `msg.from` and `msg.to` properties.","error":"msg.from or msg.to values are ignored; the node always uses its configured static range."}],"ecosystem":"npm"}