How were shift amount constants in MD5 found? The md5 specification gives a series of 4 rounds to execute over a 16-word block.

Each round has a repeating sequence of 4 shift amounts (s in [abcd k s i]) :


7, 12, 17 and 22 for the round 1
5, 9, 14 and 20 for the round 2
4, 11, 16 and 23 for the round 3
6, 10, 15 and 21 for the round 4


The specification only says:


  The shift amounts in each round have been approximately optimized, to yield a faster "avalanche effect." The shifts in different rounds are distinct.


How did they find these shift amounts? Is it a sequence like $u_n = (u_{n-1} + j) \; mod \; k$ ? What guarantees the "avalanche effect"?
The rotation countsr (together with the order of access of the 4 words of the state) are engineered for fast diffusion, as documented in RFC1321:


  The shift amounts in each round have been approximately optimized, to yield a faster "avalanche effect". The shifts in different rounds are distinct.


The general idea is to move bits to a 32-bit position on which they previously had no or little influence (limited to the effect of carry propagation in 32-bit addition, which works only to the left, and has odds like $2^{-n}$ to influence the $n$th bit on the left of a particular one); also, the choice made should facilitate efficient propagation in the next few steps. Among particularly bad choices would be to change the constants r to a mix of 1 and 31; or to all 16.

I do not know if the choice made for MD5 turned out to prevent or facilitate attacks on collision-resistance.



All the other constants in the question are chosen with a nothing-up-my-sleeve rationale; that is, convincingly unlikely to have been chosen according to a hidden property. That includes numbers computed according to a simple formula unrelated to the rest of the context (like floor(abs(sin(i + 1)) × 2^32) is); or numbers matching an obvious pattern (like being the representation of the hex string 0123456789ABCDEFFEDCBA9876543210 according to the endianness used in the context).