Hope that helps The cast of Math.random() to int is occurring before the multiplication by 6. The cast operator is of higher precedence than *. The Math.random() method returns a random number between 0 (inclusive) and 1 (exclusive), so the cast always returns 0.
hope this fix your issue The edge case occurs when you happen to generate a very small number, expressed with an exponent, like this for example 9.546056389808655e-8. Combined with parseInt, which interprets the argument as a string, hell breaks loose. And as suggested before me, it can be solved using Math.floor.
var test = 9.546056389808655e-8;
console.log(test); // prints 9.546056389808655e-8
console.log(parseInt(test)); // prints 9 - oh noes!
console.log(Math.floor(test)) // prints 0 - this is better
(Math.random()*x)+y returns numbers greater than x+y
getRandomInt('0', '256') // 1540
Math.floor(Math.random() * val.length) returns a letter not a number
hope this fix your issue What you're doing right now with val[Math.floor(Math.random() * val.length)] is picking a random character from the string val (the value of the href attribute on the a element in question). You probably want to make an array of all the images from the then use the original code to get a random one from that array
like below fixes the issue This problem is surely because math.random treats the input arguments passed in Lua 5.1 and/or 5.2. From [mathlib.c]1: As you may know in C, a standard int can represent values -2,147,483,648 to 2,147,483,647. Adding +1 to 2,147,483,647, like in your use-case, will overflow and wrap around the value giving -2,147,483,648. The end result is negative since you're multiplying a positive with a negative number.
How to explain that Observable.of(Math.random()) always returns the same value?