Generate random numbers in a range every second?

  • Thread starter -[ CaMeL ]- a55m0nk
  • Start date
C

-[ CaMeL ]- a55m0nk

I have attempted to create a javascript that displays on the page a
random number between 100,000 and 600,000, and then displays a new
random number in the same place every second after that. It is for a
fake users online for a gag website i am making in school.

any help would be much appreciated

a55m0nk
(jack)
 
L

Lasse Reichstein Nielsen

I have attempted to create a javascript that displays on the page a
random number between 100,000 and 600,000, and then displays a new
random number in the same place every second after that. It is for a
fake users online for a gag website i am making in school.

any help would be much appreciated

<p>Users online: <span id="usersFake"></span></p>
<script type="text/javascript">
var numberText = document.createTextNode("");
document.getElementById("usersFake").appendChild(numberText);
function updateFakeUsers() {
numberText.nodeValue = Math.floor(Math.random()*500000)+100000;
}
updateFakeUsers();
setInterval(updateFakeUsers,1000);
</script>

/L
 
L

Lee

-[ CaMeL ]- a55m0nk said:
I have attempted to create a javascript that displays on the page a
random number between 100,000 and 600,000, and then displays a new
random number in the same place every second after that. It is for a
fake users online for a gag website i am making in school.


If you want it to seem believable at all, you might consider
having it start at a number somewhere in that range and each
second add a random number between -10,000 and +10,000.

That will avoid jumps of several hundred thousand people per
second.
 
C

-[ CaMeL ]- a55m0nk

Lasse Reichstein Nielsen said:
<p>Users online: <span id="usersFake"></span></p>
<script type="text/javascript">
var numberText = document.createTextNode("");
document.getElementById("usersFake").appendChild(numberText);
function updateFakeUsers() {
numberText.nodeValue = Math.floor(Math.random()*500000)+100000;
}
updateFakeUsers();
setInterval(updateFakeUsers,1000);
</script>

/L

Thanks for your help it worked great :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top