Random Number in NodeJS

Hi,
I’m trying to obtain a random number taking from a variable and then using it to generate a username with a number random in the end, example “alexander.paladines55”.

In php project I normally use:
<dmx-value id="myNumber" value="<?php echo(rand(100000000,999999999)) ?>"></dmx-value>

Now in NodeJS I’m trying to obtain a random number from javascript:

<script>
  function getRndInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1) ) + min;}
    document.getElementById("numberRand").value = getRndInteger(1,99);
</script>

“numbRand” is a text input because I don’t know how to pass it into UI variable. The above works at half.
The script is placed it at end of a content page, only in the page where a actually need it
When I first time open the content page, the random number is generating into input value, but when I refresh the page I get “0” value, like if the script do not found the element to update value. No error on browser console.

How I can pass the result of the script into a UI variable <dmx-value id="var1"></dmx-value>, or if maybe exist another elegant way to generate a random number and place it into a variable or text input at least.

I’m was trying to put it into Static Event with getRndInteger(1,99) but I can’t get it works.

Community Page
Last updated: