# Node to generate Random duration in various format (HH:mm:ss, seconds, milliseconds, ISO8601)

**URL:** <https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299>\
**Category:** Share Your Nodes\
**Created:** [27 September 2024 08:40 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299 "2024-09-27T08:40:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fdecourt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdecourt/32/85290_2.png) [@fdecourt](https://discourse.nodered.org/u/fdecourt)\
**Post date:** [27 September 2024 08:40 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/1 "2024-09-27T08:40:57Z")

</div>

Hi,

I needed to generate a random duration. Instead of developing it in a function node, I developed a small and simple node to accomplish this :

> **[GitHub - fdecourt/node-red-contrib-random-duration: A Node-RED node that generates a random duration...](https://github.com/fdecourt/node-red-contrib-random-duration)**
>
> A Node-RED node that generates a random duration between a minimum and maximum value in HH:mm:ss format.

Your comments are very welcome 😉

---

<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:** [27 September 2024 08:56 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/2 "2024-09-27T08:56:12Z")

</div>

I am interested in the use case for a time duration in that format.

---

<div class="post-metadata">

**Author:** ![fdecourt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdecourt/32/85290_2.png) [@fdecourt](https://discourse.nodered.org/u/fdecourt)\
**Post date:** [27 September 2024 09:07 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/3 "2024-09-27T09:07:05Z")

</div>

Hi,  
I use this node to generate a random duration in combination with the presencefaker and Sonos Plus nodes. This setup allows me to play an MP3 file that simulates presence with everyday life sounds. I want the track to start at a random point and be played only for a duration that is also random. This way, I can have sounds that are always different without having to manage playlists.

It's indeed a good idea to add the option to choose the output format.

Regards

---

<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:** [27 September 2024 09:24 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/4 "2024-09-27T09:24:55Z")

</div>

I would have thought that you would want the duration in milliseconds or seconds for that, rather than as a string.

---

<div class="post-metadata">

**Author:** ![fdecourt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdecourt/32/85290_2.png) [@fdecourt](https://discourse.nodered.org/u/fdecourt)\
**Post date:** [27 September 2024 09:25 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/5 "2024-09-27T09:25:50Z")

</div>

> [@Colin](#):
>
> would have thought that you would want the duration in milliseconds or seconds for that, rather than as a string.

Hi, nop, the Sonos Plus node needs a string in HH:mm:ss.  
I just update the node to select the wanted format (including milliseconds and seconds)

---

<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:** [27 September 2024 09:50 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/6 "2024-09-27T09:50:54Z")

</div>

> [@fdecourt](#):
>
> the Sonos Plus node needs a string in HH:mm:ss.

I find that very strange.

---

<div class="post-metadata">

**Author:** ![fdecourt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdecourt/32/85290_2.png) [@fdecourt](https://discourse.nodered.org/u/fdecourt)\
**Post date:** [27 September 2024 10:11 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/7 "2024-09-27T10:11:14Z")

</div>

Maybe, but here : [A.1 Universal Node · hklages/node-red-contrib-sonos-plus Wiki · GitHub](https://github.com/hklages/node-red-contrib-sonos-plus/wiki/A.1-Universal-Node#groupseek)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3013e672ea44ddf1c0d769677bfe58e93446654.png)

---

<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:** [27 September 2024 11:07 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/8 "2024-09-27T11:07:41Z")

</div>

I was not doubting what you said, just commenting that it is surprising not to at least give the option of a duration in seconds.

---

<div class="post-metadata">

**Author:** ![fdecourt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdecourt/32/85290_2.png) [@fdecourt](https://discourse.nodered.org/u/fdecourt)\
**Post date:** [27 September 2024 15:47 UTC](https://discourse.nodered.org/t/node-to-generate-random-duration-in-various-format-hhss-seconds-milliseconds-iso8601/91299/9 "2024-09-27T15:47:55Z")

</div>

Maybe because it is more easy to manipulate music with this format, as it is more humanly understable 😉
