# Output sequentially and randomly to 3 different nodes

**URL:** <https://discourse.nodered.org/t/output-sequentially-and-randomly-to-3-different-nodes/79564>\
**Category:** General\
**Created:** [3 July 2023 20:19 UTC](https://discourse.nodered.org/t/output-sequentially-and-randomly-to-3-different-nodes/79564 "2023-07-03T20:19:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [3 July 2023 21:36 UTC](https://discourse.nodered.org/t/output-sequentially-and-randomly-to-3-different-nodes/79564/2 "2023-07-03T21:36:58Z")

</div>

The simplest way I've found to route messages to random output ports is to use the `switch` node that compares a JSONata expression against the 3 possible output values -- [this post](https://discourse.nodered.org/t/switch-node-jsonata-magic/12943/4) uses that technique to perform a "round-robin" effect...

Your case sounds a bit more complicated in that it seems like you will need to keep track of the previously sent messages. So if the last event turned on elements #2 and #1, and you wanted to leave only 1 of them on, then you would need to randomly turn off either #2 or #1 (since turning off #3 would effectively be a no-op, right?). Or you could design the flow to always turn every element "off" just before sending a message to randomly enable 1, 2 or 3 elements -- although I would imagine that the extra cycling would not be good for extending the element lifespan either.

---

_[View the full topic](https://discourse.nodered.org/t/output-sequentially-and-randomly-to-3-different-nodes/79564)._
