I would like to generate a random number on my site without having to press a button

I want to have a 4 digit (0000-9999) random number on my page WITHOUT having to press a button.

Hello ryan greenstein,

take a look here…
https://russian-dima.wixsite.com/meinewebsite/random-numbers-strings

https://webiya.wixsite.com/rnd-number-example

If you want it happen immediately after site is loaded without a buttton, then just start it in the onLoad function.

$w.onReady(function () { })

Thank you russian-dima, I actually looked at both of those. I tried them, but it wouldn’t work for me.

Why?

So… I don’t know. I matched all of the #button1’s and the #text1’s but it still didn’t work.

Show your relevant code…

Ok

function getRandomInRange(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1 )) + min;
}

function getRandomString() {
return Math.random().toString( 36 ).substr( 2 , 8 );
}

$w.onReady( function () {
$w( ‘#JOIN’ ).onClick(() => {
#RandomNumber’ .text = getRandomInRange( 0 , 9999 ).toString();
$w( ‘#ID’ ).text = getRandomString().toString();

}); 

});

Check it out…

function getRandomInRange(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
 return Math.floor(Math.random() * (max - min + 1)) + min;
}

function getRandomString() {
 return Math.random().toString(36).substr(2, 8);
}

$w.onReady(function () {
    $w('#JOIN').onClick(() => {
    $w('#RandomNumber').text = getRandomInRange(0, 9999).toString();
    $w('#ID').text = getRandomString().toString();

    });
});

Ok

Thank you so much!

It works?
If you liked my answer —> think about to give a like xD​:grin: (or even “BEST-ANSWER”) ? :yum:

I did and everything to rate it the best. Have a good night! (in est)

i did all

I want to genrate 10 digit rendom number

Nice idea! :blush: Could be very useful.

The IDEA was gone! :grin: :blush: → but i already memorized it :grin: