Answer the question
In order to leave comments, you need to log in
Why doesn't math work in js?
All in all, this is the thing. There is a piece of code written in as3 and its analogue in haxe.
I needed to use it in js, so I rewrote it, but it doesn't work.
Then I took haxe and compiled it into js, but the problem remained the same.
public static function getInt(min:Int, max:Int):Int {
seed = 214013 * seed + 2531011;
return min+(seed ^ (seed>>15))%(max-min+1);
}
function getInt(min, max) {
seed = 214013 * seed + 2531011;
return min+(seed ^ (seed>>15))%(max-min+1);
}
Answer the question
In order to leave comments, you need to log in
The bit operators make any number a 32-bit integer. When seed becomes greater than 4294967295, then 0 is used instead.
upd seed ^ (seed >> 15) becomes always 0.
upd2 when seed > 2 32 seed >> 15 is always 0, when seed > 2 54 seed ^ 0 is always 0
upd3 after experimenting, I found out that it is essentially correct, but inaccurate, numbers greater than 2 32 + 53 binary operators turn into 0
What is the seed variable, or rather what type is it, you can try to wrap it in IntegerparseInt(seed);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question