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.

npm install node-red-contrib-fff-random-number

node-red-contrib-fff-random-number

CI npm version License: ISC

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 inject node that triggers the default configuration.
  • An inject node that overrides min, max and decimals via the message.
  • A debug node to inspect msg.payload.

Notes and caveats

  • Default source is not cryptographically secure. With cryptoSecure disabled (the default), the node uses Math.random(). Do not use that mode for tokens, keys, or any security-sensitive value.
  • cryptoSecure is not a key generator. It draws from crypto.randomBytes, which is suitable for non-statistical use cases where Math.random would be too biased, but it is not a substitute for purpose-built credential or token generators.
  • max and rounding. When decimals > 0, the result is rounded with Number.prototype.toFixed. Values close to max can round up to max itself.
  • min > max. The node treats [min, max] as an interval and does not reorder. If min > 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.max or msg.decimals is present but not coercible to a finite number, the node emits node.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:

  1. Open the flow file (.json) or the Node-RED editor.
  2. Replace every "type": "random-number" with "type": "fff-random-number".
  3. 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

Node Info

Version: 2.0.0
Updated 12 hours ago
License: ISC
Rating: not yet rated

Categories

Actions

Rate:

Downloads

6 in the last week

Nodes

  • fff-random-number

Keywords

  • node-red
  • random
  • number
  • generator
  • crypto
  • fff

Maintainers