There are random mutations, that is the idling scenario I used and yes, even random mutation likely builds advantages into an organism, but there is a second set of mutations that somehow experience their environment and react to the stimulus of change. These mutations are far more stimulated than the random set. Such as an ice-age rhinos becoming great shaggy beasts. It is likely that the DNA for producing abundant hair was triggered by the event and changes occurred at a far more rapid rate than standard mutation.
The atomic composition of DNA seems to read the needs of the entire organism.
It can be random and accidental, but the real changes are far more mysterious. It may explain cladogenesis and the rapid evolution of new ecosystems after cosmic catastrophes.
A third process may also exist and that is what rolls out complexity leading to a sentient, conscious being able to manipulate nature, explore the universe and understand its nature and recognise that there is a Cause for their existence, but this is far more contentious and leads to religion if not handled carefully.