Best way to establish a random (range) injection like node?

Best way to establish a random (range) injection like node? Need a inject like node, that can have a random time range. For example, node generates message at 1 second, then 3 seconds later, then 2 seconds later, etc., within a qualified range.

Maybe use a function node with a recursive setTimeout function that uses a random var?

Or a inject that creates a random delay that feeds into a delay node.

[{"id":"3e45301a.4c0058","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"delay","v":"$ceil($random()*10)*1000","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1220,"wires":[["c7b96800.58c8e"]]},{"id":"c7b96800.58c8e","type":"delay","z":"57675e72.26a0d8","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":340,"y":1220,"wires":[["b84dcbfc.816ad"]]},{"id":"b84dcbfc.816ad","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":1220,"wires":[]}]

this will give a delay random set between 1 and 10 seconds

1 Like

Nice forgot that jsonata can do random to.
Very clean :+1:t2: Those are always those small things where jsonata comes in really handy and i have to remind myself to use it more.

So much to remember, so little gray matter.

[edit]This may work better

[{"id":"6923bf.c6d0e44","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":80,"y":1340,"wires":[["c7b96800.58c8e"]]},{"id":"3e45301a.4c0058","type":"inject","z":"57675e72.26a0d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":1280,"wires":[["8a78a9a6.792a38"]]},{"id":"8a78a9a6.792a38","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"$ceil($random()*10)*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":1200,"wires":[["c7b96800.58c8e"]]},{"id":"c7b96800.58c8e","type":"delay","z":"57675e72.26a0d8","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":1240,"wires":[["8a78a9a6.792a38","b84dcbfc.816ad"]]},{"id":"b84dcbfc.816ad","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":1280,"wires":[]}]