Getting deep into JSONata now
In this flow an inject node generates random numbers fro 0 to 9.
The change node checks if the number is already in the array and appends it if not.
After a high enough number of injects, the array is at it's maximum of 10 elements (0 -9), and
will not grow at all.
[{"id":"8a098f827b12daf6","type":"tab","label":"Flow 9","disabled":false,"info":"","env":[]},{"id":"3e32b9a35b640723","type":"inject","z":"8a098f827b12daf6","name":"Inject Random number 0-9","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$floor($random()*10)\t","payloadType":"jsonata","x":170,"y":140,"wires":[["9fc45dc141a86816"]]},{"id":"9fc45dc141a86816","type":"change","z":"8a098f827b12daf6","name":"","rules":[{"t":"set","p":"array","pt":"global","to":"(payload in $globalContext(\"array\")) ? $globalContext(\"array\"): $append($globalContext(\"array\"), [payload])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":140,"wires":[[]],"info":"Check"},{"id":"7f35d69c6159dba7","type":"comment","z":"8a098f827b12daf6","name":"CHeck if number is in array. If not add it.","info":"CHeck if number is in array","x":510,"y":80,"wires":[]}]
@dynamicdave's methods in JavaScript might be easier to implement for you!