In the AsemblyScript book it mentions that Math.random()
takes a seed and returns an <f64>
value. I just need a random <u64>
value. How do I achive that?
I tried
(Math.random() * 0xffffffffffffffff) as u64
<u64>(<f64>Math.random() * <f64>0xffffffffffffffff)
(<f64>Math.random() * <f64>0xffffffffffffffff) as u64
or with f64.MAX_VALUE
in the place of 0xffffffffffffffff
and whatnot.
but I keep getting 0.
I can get <U32>
random values just fine but When I multiply two <U32>
random values I get like 52 random bits and the rest is 0. I understand why this happens from my JS background, still from the typed struct and lower level abstractions of AS I hoped to get no friction.
How exactly I can obtain a <u64>
random integer properly with AssemblyScript?
Edit:
I think I finally got it doing like
(<u64>(Math.random() * u32.MAX_VALUE) << 32) | <u32>(Math.random() * u32.MAX_VALUE)
but is this really how it should be done?