# Random Message Routing

**URL:** <https://discourse.nodered.org/t/random-message-routing/14266>\
**Category:** General\
**Created:** [13 August 2019 03:17 UTC](https://discourse.nodered.org/t/random-message-routing/14266 "2019-08-13T03:17:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheminasalam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sheminasalam/32/8981_2.png) [@sheminasalam](https://discourse.nodered.org/u/sheminasalam)\
**Post date:** [13 August 2019 03:17 UTC](https://discourse.nodered.org/t/random-message-routing/14266/1 "2019-08-13T03:17:21Z")

</div>

Is there any node which has multiple outputs and which can route an incoming payload to anyone of the outputs randomly.

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [13 August 2019 03:36 UTC](https://discourse.nodered.org/t/random-message-routing/14266/2 "2019-08-13T03:36:21Z")

</div>

What about a Function node with some code to create the "randomness"?

---

<div class="post-metadata">

**Author:** ![sheminasalam](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sheminasalam/32/8981_2.png) [@sheminasalam](https://discourse.nodered.org/u/sheminasalam)\
**Post date:** [13 August 2019 04:22 UTC](https://discourse.nodered.org/t/random-message-routing/14266/3 "2019-08-13T04:22:05Z")

</div>

that is possible but i have no luck in getting it right and working

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [13 August 2019 04:25 UTC](https://discourse.nodered.org/t/random-message-routing/14266/4 "2019-08-13T04:25:53Z")

</div>

You know what the next step is then 🙂

Share what didn't work, so others can assist.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 August 2019 05:59 UTC](https://discourse.nodered.org/t/random-message-routing/14266/5 "2019-08-13T05:59:11Z")

</div>

JSONata has a random function I think too so you could use the change node to add a random number to your incoming msg then use the switch node with a range of numbers.

I think there may be a random node as well. Have you checked the flows site?

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [13 August 2019 06:21 UTC](https://discourse.nodered.org/t/random-message-routing/14266/6 "2019-08-13T06:21:25Z")

</div>

Hi,  
You could simply use my [node-red-contrib-msg-router](https://github.com/bartbutenaers/node-red-contrib-msg-router#random-routing).  
One of the many available routing algorithms is random routing.  
Bart

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [13 August 2019 06:32 UTC](https://discourse.nodered.org/t/random-message-routing/14266/7 "2019-08-13T06:32:48Z")

</div>

And because everyone has "stepped in" to spoil my Function party 🙁, you could achieve want you wanted in a Function node using math.random and a switch statement directing the msg randomly to x outputs. Just sayin' 😉
