Betti numbers of deterministic and random sets in semi-algebraic and o-minimal geometry