3 ms·
> If the probability is that high, then even if x was just { return 123 } you shouldn't assume it will work. if x -> { return 123 } then callers can 100% assum
by preseinger 3y ago
> If the probability is that high, then even if x was just { return 123 } you shouldn't assume it will work.
if x -> { return 123 } then callers can 100% assume it will work
what is the alternative? how could callers de-risk the case when a solar ray flips a bit to make x not return 123?
they can't, because they don't have access to an execution model outside of the semantics of the language, and those language semantics literally guarantee x will return 123
this is literally basic computer science material
> if you replace that code with if (secure_rand_u128() == 0) { panic("boom") }, then it would be safe to assume it won't panic.
secure_rand_u128 returns, presumably, a random unsigned 128 bit integer
unsigned 128 bit integers can be any value between 0 and 340282366920938463463374607431768211455 -- and one of those possible return values is 0
if i call secure_rand_u128, then it absolutely can return 0, and code which assumes that it will never return 0 is, factually, buggy
if you want to make the assumption that secure_rand_u128 will never return 0, then you have to justify that assumption in the context of your specific use case -- it absolutely cannot be assumed in the general case
without qualifications -- P(x|x>0) != P(0)