Trial-and-error plays a role, but AI does not lean on it as heavily as you imply. Certainly, no more than an average human.