Joob Posted September 9, 2017 Share Posted September 9, 2017 Hello, How can I put the most random script, and not only a count of 5 in 5 .. I wanted, for example, a count of 5 after 7, after 3, after 2, after 6 or 15 etc .... numbers .. a more random count and not only 5 in 5 or 4 in 4 etc. .. <script> function handleTickInit(tick) { // update the value every 5 seconds var interval = Tick.helper.duration(5, 'seconds'); // value to add each interval var valuePerInterval = 5; // offset is a fixed date in the past var offset = Tick.helper.date('2017-03-01'); // uncomment lines below (and comment line above) if you want offset be set to the first time the user visited the page // var offset = parseInt(localStorage.getItem('tick-value-counter-offset') || Date.now(), 10); // localStorage.setItem('tick-value-counter-offset', offset); // start updating the counter each second Tick.helper.interval(function(){ // current time in milliseconds var now = Date.now(); // difference with offset time in milliseconds var diff = now - offset; // total time since offset divide by interval gives us the amount of loops since offset var loops = diff / interval; // this will make sure we only count completed loops. loops = Math.floor(loops); // multiply that by the value per interval and you have your final value tick.value = loops * valuePerInterval; }, 1000); } </script> I do not know if you understood the issue.. Quote Link to comment https://forums.phpfreaks.com/topic/304920-more-random-count/ Share on other sites More sharing options...
denno020 Posted September 10, 2017 Share Posted September 10, 2017 I'm struggling to figure out which numbers you want to be random.. But, for random numbers you can just use the Math object, and the random() function. That will return a decimal between 0 and 1, so you'll need to do some further work to get a whole number that is between some lower and upper limits. For setting those limits, the Mozilla Developer Network page for the Math.random() function has some great examples Denno Quote Link to comment https://forums.phpfreaks.com/topic/304920-more-random-count/#findComment-1551113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.