Randomly increase a value

Hello!

Is it possible to randomly increase a value from an array and pass it on?

I have an array with 150-200 values (number and name) and that he then chooses one at random.

You mean something like this?

[{"id":"f71482f179f781d6","type":"function","z":"52be70f9bee628c4","name":"","func":"\n\nlet arr = [];\nflow.set(\"arr_length\",150);\nflow.set(\"your_value\", 0);\n\n// this is generating an array with random entries. just replace it with your array\nfor(let i = 0; i < flow.get(\"arr_length\"); i++){\n    arr.push( {\"number\": Math.round(Math.random() * 100 ), \"name\": \"name \"+i} );\n}\n\nflow.set(\"arr\", arr);\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":280,"wires":[[]]},{"id":"85edc692aea757fa","type":"inject","z":"52be70f9bee628c4","name":"init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":270,"y":280,"wires":[["f71482f179f781d6"]]},{"id":"98b11ab0fe6147bb","type":"inject","z":"52be70f9bee628c4","name":"increase your_value","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":230,"y":340,"wires":[["73867c393218ced3"]]},{"id":"73867c393218ced3","type":"function","z":"52be70f9bee628c4","name":"","func":"let index = Math.round(Math.random() * (flow.get(\"arr_length\") -1) );\nflow.set(\"your_value\", flow.get(\"your_value\") + flow.get(\"arr\")[index].number );\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":340,"wires":[["8218ca6c4360e21e"]]},{"id":"8218ca6c4360e21e","type":"change","z":"52be70f9bee628c4","name":"increased value","rules":[{"t":"set","p":"payload","pt":"msg","to":"your_value","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":340,"wires":[["5369f47db751b73b"]]},{"id":"5369f47db751b73b","type":"debug","z":"52be70f9bee628c4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":340,"wires":[]}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.