Need help with random output on random timer within dynamically set ranges

I have tried various nodes and flows with no luck and I am hitting a wall on ideas on how to do this.
My goal is to have an end output that is randomly between 0 and 100. However, I would like that to be able to be dynamically set using two sliders that are on the UI for Min and Max so that out of the 0-100, the user could set it to be only 25-75 or whatever they choose to set.
Additionally, I would like a looping random timer that goes from 1-60 seconds. This would also have Min and Max sliders so the user can set it to be anywhere within the range they set.
End result would be a random number between the user set Min and Max with that number changing at a random interval also set with Min and Max sliders.
Thank you in advance for any help, suggestions or flows.

edit - It does not have to be sliders, it can be a drop down or any other UI input

Hi @omono35

Your project doesn't seem to be too exotic - but doable.
There are nodes that create random numbers, nodes that create UI input options, and so on ...
Thus: What exactly is your issue?

You can do this with a join and change node with a JSONata expression

$round(
   $random() * ($$.payload.max - $$.payload.min)
) + $$.payload.min
[{"id":"2a552eda3db4f7f2","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"min","payload":"40","payloadType":"num","x":90,"y":2720,"wires":[["9c550c912de39109"]]},{"id":"9c550c912de39109","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":290,"y":2740,"wires":[["bf7b8b8311491d67"]]},{"id":"9c95755e88b3a4a8","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"max","payload":"52","payloadType":"num","x":85.33332824707031,"y":2766.666748046875,"wires":[["9c550c912de39109"]]},{"id":"bf7b8b8311491d67","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(\t   $random() * ($$.payload.max - $$.payload.min)\t) + $$.payload.min","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":2760,"wires":[["204c998ddf383cfd"]]},{"id":"204c998ddf383cfd","type":"debug","z":"b9860b4b9de8c8da","name":"debug 296","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":2700,"wires":[]}]

You can then use the output to create your timer with any of the timer nodes or a trigger or delay nodes.

I have not been able to get it to do more than one loop. Unfortunately I have gotten frustrated and deleted what I had.
Basically I would get it to spit out the random output at the start using defined min and max, and then it would pick a random time and spit out the same number as before and stop.
I have tried using the Random node as well as an Event node. I am thinking it might need more scripted functions using random generators, but I am terrible at scripting within the function nodes.

Thank you E1cid,
That is a good start. I have actually gotten about that far before and I guess I should have said that in my opening post. The problem I have is actually taking something like that and combining it all together for the timer and the output to continue looping until it is stopped.

The description of your timer was to vague to offer any more advise on, you will need to explain alot more about this looping timer to help more.

Sorry.
For example I would have an LED that has a brightness level going from 0-100. I would like to set an input using the UI of say 25-60 that will randomly pick the brightness. Then I would have a timer start that would be from 1-60 seconds. But I would set values using the UI of 30-50 seconds and hit start. Then the light would go to 30 and wait 40 seconds then change to 26 and wait 35 seconds and continue randomizing both the brightness and time until it is stopped. Then before starting it again, be able to change the min and max of the brightness and the min and max of the time to new settings and then start it.

Still a little vague. This will set output to random say between 40 and 60. It will turn on light at 45. Then wait for random time between 1 and 10, before, say 5 outputting another number 56, the wait 8, then out put 42 etc....

[{"id":"2a552eda3db4f7f2","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"min","payload":"40","payloadType":"num","x":130,"y":2700,"wires":[["9c550c912de39109"]]},{"id":"9c550c912de39109","type":"join","z":"b9860b4b9de8c8da","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":310,"y":2720,"wires":[["bf7b8b8311491d67"]]},{"id":"9c95755e88b3a4a8","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"max","payload":"60","payloadType":"num","x":125.33332824707031,"y":2746.666748046875,"wires":[["9c550c912de39109"]]},{"id":"4dc37b6418bf46a0","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"minR","payload":"4","payloadType":"num","x":130,"y":2820,"wires":[["9c550c912de39109"]]},{"id":"9d346a52e384de2f","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"maxR","payload":"10","payloadType":"num","x":135.3333282470703,"y":2866.666748046875,"wires":[["9c550c912de39109"]]},{"id":"bf7b8b8311491d67","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"($round(\t   $random() * ($$.payload.maxR - $$.payload.minR)\t) + $$.payload.minR) * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":2800,"wires":[["100dda2cc4b1e45b"]]},{"id":"100dda2cc4b1e45b","type":"trigger","z":"b9860b4b9de8c8da","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"10","extend":false,"overrideDelay":true,"units":"s","reset":"false","bytopic":"all","topic":"topic","outputs":2,"x":530,"y":2720,"wires":[["6cd544fe0ca57db5"],["bf7b8b8311491d67"]]},{"id":"58adf7909d5dbdef","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":310,"y":2660,"wires":[["100dda2cc4b1e45b"]]},{"id":"6cd544fe0ca57db5","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$round(\t   $random() * ($$.payload.max - $$.payload.min)\t) + $.payload.min","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":2720,"wires":[["204c998ddf383cfd"]]},{"id":"204c998ddf383cfd","type":"debug","z":"b9860b4b9de8c8da","name":"debug 296","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":890,"y":2720,"wires":[]}]

[edit] remove unneeded trigger node.

I think I can work with what you have given me.
I had never had much luck with the join node and never tried JSON Expressions with it.
Thank you very much for the help.

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