Hello
I'm sorry but I don't understand that part
// Step 3. Calculate crash = r / 2^52, uniformly distributed in [0; 1)
const twoPower52 = Math.pow(2, nBitsToUse);
let crash = r / twoPower52;
I don't understand why we need to divide this number by 2^52?
The result will always be <=1, no?
I think I'm the original author of this, as it appears to be copied from bustabit. I was just trying to convert a sha256 hash into a number between 0 and 1 (and then turn that into a multiplier). The most obvious and correct way to do this would be simply get the hash (as a number) and then divide by 2^256. But as the original bustabit was written in javascript (both the server and client), I wanted to approximate that in a simple way. Javascript's only number type was a 64 bit floating point, which means it can only represent integers accurately up to 2^53 - 1. So the cleanest number less than that is 2^52, which is the max number if you read the 13 hex characters of a hash.
So basically the logic is "read the first 13 hex characters from a hash, parse as a number, divide by 2^52" and now you have a number scaled between 0 and 1.
But it's really just an artifacts of the limitations I was working with at the time (e.g. python if i was working in python, I would've just done divided the whole thing. Or if i was working with a language with proper 64 bit numbers, would've done that, etc. )
Thank you very much for these very precise and clear clarifications RHavar.
I'm sorry for these questions but I'm trying to understand how that works.