# Random function problem ,need help

**URL:** <https://discourse.nodered.org/t/random-function-problem-need-help/8882>\
**Category:** General\
**Created:** [12 March 2019 12:53 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882 "2019-03-12T12:53:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sana\_sabah86](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sana\_sabah86](https://discourse.nodered.org/u/sana_sabah86)\
**Post date:** [12 March 2019 12:53 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/1 "2019-03-12T12:53:49Z")

</div>

In this node, red I want to generate random number between 0-10 and if the number is less than 5 I want to output: the ((generated number from the function )) along with string message such as” less than 5”  
for example 🙂 4 less than 5  
I can only output the generated number from the random function and I don’t know how to output string with it, I need help please.

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/48d3aa3976dacba9a8808aadaf8fd62c2e9c36ad.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 March 2019 13:23 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/2 "2019-03-12T13:23:31Z")

</div>

> [@sana\_sabah86](#):
>
> along with string message such as” less than 5”

What do you by 'along with'? Do you mean a single string containing the number and text, or you want the number and message separately in one message?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [12 March 2019 14:55 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/3 "2019-03-12T14:55:40Z")

</div>

[https://www.google.co.uk/search?q=append+string+javascript&ie=UTF-8&oe=UTF-8&hl=en&client=safari](https://www.google.co.uk/search?q=append+string+javascript&ie=UTF-8&oe=UTF-8&hl=en&client=safari)

---

<div class="post-metadata">

**Author:** ![sana\_sabah86](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sana\_sabah86](https://discourse.nodered.org/u/sana_sabah86)\
**Post date:** [13 March 2019 03:27 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/4 "2019-03-13T03:27:02Z")

</div>

When I try to use (+) operator, I get an error as you see

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9c0481aa73aad89f41bb9877be6a4a09733b9501.png)

---

<div class="post-metadata">

**Author:** ![sana\_sabah86](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sana\_sabah86](https://discourse.nodered.org/u/sana_sabah86)\
**Post date:** [13 March 2019 03:57 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/5 "2019-03-13T03:57:10Z")

</div>

> [@Colin](#):
>
> single string containing the number and text

yes mean single string containing the number and text.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [13 March 2019 07:34 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/6 "2019-03-13T07:34:16Z")

</div>

You always need to return objects not variables.

But you should be able to concatenate within that object

eg

number = 5;  
msg.payload = “the number is :” + number;  
return msg;

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 March 2019 10:03 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/7 "2019-03-13T10:03:42Z")

</div>

@sana_sabah86 - function debugging hint; do display sometthing in the debug log you can use:  
`node.warn("randon is: " + rnd);`  
and it will show with all the other debug messages.

---

<div class="post-metadata">

**Author:** ![sana\_sabah86](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sana\_sabah86](https://discourse.nodered.org/u/sana_sabah86)\
**Post date:** [18 March 2019 03:41 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/8 "2019-03-18T03:41:54Z")

</div>

it worked! thank you so much for your helo

---

<div class="post-metadata">

**Author:** ![sana\_sabah86](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sana\_sabah86](https://discourse.nodered.org/u/sana_sabah86)\
**Post date:** [18 March 2019 03:43 UTC](https://discourse.nodered.org/t/random-function-problem-need-help/8882/9 "2019-03-18T03:43:22Z")

</div>

thank you
