node-red-contrib-fff-random-number 2.0.0
Node-RED node that generates random numbers with configurable range, precision and an optional cryptographically secure source.
node-red-contrib-fff-random-number
A Node-RED node that generates a pseudo-random number within a configurable
range and decimal precision. The result is written to msg.payload as a
Number and shown in the node status.
The fff prefix stands for FishFarmFeeder, the project this node was
originally built for. The node itself is general-purpose.
Installation
Recommended: install from the Node-RED palette manager
(Menu → Manage palette → Install) and search for
node-red-contrib-fff-random-number.
Manual install from your Node-RED user directory (default ~/.node-red on
Linux/macOS, %HOMEPATH%\.node-red on Windows):
npm install node-red-contrib-fff-random-number
Restart Node-RED. The node appears in the function category as
random number.
Configuration
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | "" |
Label shown in the editor. |
min |
number | 0 |
Lower bound of the generated range. |
max |
number | 1 |
Upper bound of the generated range. |
decimals |
integer | 0 |
Decimal places to keep. Valid range: 0–20. |
cryptoSecure |
boolean | false |
If true, uses crypto.randomBytes instead of Math.random. |
Per-message overrides
Any field above can be overridden on a per-message basis. If the property is not set on the message, the editor value is used.
| Message property | Overrides |
|---|---|
msg.min |
min |
msg.max |
max |
msg.decimals |
decimals |
If an override cannot be coerced to a finite number, the node calls
node.error() and does not emit a message.
Output
The incoming message is forwarded unchanged except for:
msg.payload— the generated number (Number).
The status badge shows the last value produced.
Example
A working flow is included in
examples/basic-flow.json. Import it from
Node-RED with Menu → Import → select file. It contains:
- An
injectnode that triggers the default configuration. - An
injectnode that overridesmin,maxanddecimalsvia the message. - A
debugnode to inspectmsg.payload.
Notes and caveats
- Default source is not cryptographically secure. With
cryptoSecuredisabled (the default), the node usesMath.random(). Do not use that mode for tokens, keys, or any security-sensitive value. cryptoSecureis not a key generator. It draws fromcrypto.randomBytes, which is suitable for non-statistical use cases whereMath.randomwould be too biased, but it is not a substitute for purpose-built credential or token generators.maxand rounding. Whendecimals > 0, the result is rounded withNumber.prototype.toFixed. Values close tomaxcan round up tomaxitself.min > max. The node treats[min, max]as an interval and does not reorder. Ifmin > max, you will get values in[max, min]with the sign of(max - min)applied. Validate inputs upstream if this matters.- Invalid overrides cause an error. If
msg.min,msg.maxormsg.decimalsis present but not coercible to a finite number, the node emitsnode.error()and does not forward the message.
Requirements
- Node-RED ≥ 3.0
- Node.js ≥ 18
Migrating from 1.x
The 2.0 release renames the registered node type from random-number to
fff-random-number so it cannot collide with other community packages.
Flows exported under 1.x reference the old type and will fail to load
until they are updated:
- Open the flow file (
.json) or the Node-RED editor. - Replace every
"type": "random-number"with"type": "fff-random-number". - Re-deploy.
The configuration fields (min, max, decimals) and the message
overrides are unchanged. A new optional field, cryptoSecure, is added.
Contributing
Bug reports and pull requests are welcome. See
CONTRIBUTING.md for the workflow.
License
ISC © Carlos Fontán