# Question about node-red-node-random

**URL:** https://discourse.nodered.org/t/question-about-node-red-node-random/3398
**Category:** General
**Created:** [23 September 2018 22:47 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398 "2018-09-23T22:47:22Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [23 September 2018 22:47 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/1 "2018-09-23T22:47:22Z")

</div>

According to the README for `node-red-node-random`, in floating-point mode this node gives a random output, x, that is strictly between the given maximum and minimum values, that is, min \< x \< max. However, everything I've read about the Math.random() method (for instance, [https://www.w3schools.com/jsref/jsref\_random.asp](https://www.w3schools.com/jsref/jsref_random.asp)) implies that the lower limit is included, that is min ≤ x \< max. The difference might seem trivial, but it does matter for a flow I'm developing. Is the README wrong, or have I mis-read something in the code?

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [24 September 2018 05:20 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/2 "2018-09-24T05:20:10Z")

</div>

Even more interesting is the help screen

It behaves differently based on what you are asking the output to be formatted as !!

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

Craig

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [24 September 2018 05:23 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/3 "2018-09-24T05:23:17Z")

</div>

Here is the actual JS could explain some of the reasons

```auto
module.exports = function(RED) {
    "use strict";
    function RandomNode(n) {
        RED.nodes.createNode(this,n);
        this.low = Number(n.low || 1);
        this.high = Number(n.high || 10);
        this.inte = n.inte || false;
        this.property = n.property||"payload";
        var node = this;
        this.on("input", function(msg) {
            var value;
            if (node.inte == "true" || node.inte === true) {
                value = Math.round(Number(Math.random()) * (node.high - node.low + 1) + node.low - 0.5);
            }
            else {
                value = Number(Math.random()) * (node.high - node.low) + node.low;
            }
            RED.util.setMessageProperty(msg,node.property,value);
            node.send(msg);
        });
    }
    RED.nodes.registerType("random",RandomNode);
}

```

Craig

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 September 2018 06:48 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/4 "2018-09-24T06:48:14Z")

</div>

Yes it behaves differently on purpose.  
And yes in float mode it does include the minimum.

The thinking being that for non computer folk, if I want say a dice to give me a number from 1 to 6 I would ask for that not 1 to 7.

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 September 2018 18:02 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/5 "2018-09-24T18:02:10Z")

</div>

> [@dceejay](#):
>
> And yes in float mode it does include the minimum.

Thanks, Dave. Would you mind correcting the documentation?

I also wonder about using the Number() method in the code. Is that just to protect against some sort of wonkiness in the random number generator?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 September 2018 18:48 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/6 "2018-09-24T18:48:02Z")

</div>

done. pushed as v0.1.1

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 September 2018 18:54 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/7 "2018-09-24T18:54:08Z")

</div>

> [@dceejay](#):
>
> done. pushed as v0.1.1

Thanks, but (oops!) not fixed in the README...

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [24 September 2018 19:04 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/8 "2018-09-24T19:04:44Z")

</div>

do people read them ? 😉 v0.1.2

---

<div class="post-metadata">

### Author: ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)
#### Post date: [24 September 2018 19:18 UTC](https://discourse.nodered.org/t/question-about-node-red-node-random/3398/9 "2018-09-24T19:18:31Z")

</div>

We can always hope 😬
