javascript - Generate incremented random numbers between 0 to 100 every second where new number should be greater than the previous nymber -
I need a javascript, where in every second call I get a random number between 0-100, where the current number Must have more number than previous I wrote a code to get random numbers in every second but it was stuck on generating it with increments.
& lt; Script & gt; Var span = document.getElementsByTagName ("span") [3]; Var I = 100; (FunctionRandanumber () {var a = Math.floor ((Math.Rendam) * i) +1); Span.innerHTML = "RandomNumber:" + a; Set timeout (rand number, 1000);}) ();
Note: The number randomly arises. Examples might be: 2,5,7,8,22,23,30,78,88 ..... < Div class = "post-text" itemprop = "text">
You should not create a new number between zero and your maximum ( i ), but only the last created number ( Last numberumber ) and max ( i ) You may also want to stop when the random number reaches the maximum. var span = document.getElementsByTagName ("span") [3], i = 100, lastNumber = 0; Function Randomumber () {Final number = Final number + Math.flur (Math.Random) * (i - Final number) + 1); Span.innerHTML = Final number; If (last number & lt; i) {setTimeout (RAND NO, 1000); }} Randanumber ();
For the comments and requirements of at least steps till the maximum access to the maximum:
In each repetition, increase only a random number 1 and the value between ( (max - minimum) / step . This is very similar to the same code as above. var span = Document.getElementsByTagName ("span") [3], max = 100, min = 0, final number = 0, minstep = 30; // How many wide average steps can be the most? Var stepWidth = (max - n Untm) / minute stops; (Randnanbr, 1000);}} Randnmber (last number, maximum); (Randnanbr, max) {setTimeout; randNumber ()); );
Comments
Post a Comment