I think it bears mentioning that nothing in nature is ever done with a purpose, including, in this case, the evolution of species by natural selection. Of course, through natural selection, things which are useful tend to remain, and things which are not useful tend to disappear. In that sense, I suppose you could describe certain adaptations as “purposeful,” to the extent they are useful in passing genes to the next generation, but it’s an anthropomorphic way of describing the phenomenon and therefore misleading.
All things in nature happen randomly in proportion to their probability of occurring, including gene mutations and gene selection from parents. When genes randomly vary, those genes which prevent themselves from being passed on to offspring are less likely to be replicated, and they might eventually die out, or the environment could change, rendering them harmless or useful, allowing them to persist. Evolution is usually, but not always, the demise of the least fit.
Occasionally, a very harmful trait will appear in an individual with a bunch of other traits that compensate for the harmful trait, so the harmful trait is passed on. Sometimes, an incredibly useful trait appears in an otherwise unfit individual, and that trait is lost. Sometimes, luck may favor an unfit individual over a fit one. A seed with genes statistically most likely to be passed on to offspring may nonetheless by chance be eaten by squirrels before germinating. It is likewise very common for traits which are not useful but also not harmful to be passed to offspring. There isn’t enough selective pressure to kill them off, so they persist even though they serve no purpose.