All changes to these bits are random. But the useful changes get passed on via natural selection. Eventually, eye-like changes form randomly in the DNA code, & are passed on & refined.
Yeah that's a totally unproven theory I strongly suspect to be wrong.