Sure it can ricochet off the ground, or anything else for that matter, plus the direction will be random. "Grazing fire" is a different matter, and often done intentionally by firing nearly parallel to the ground. While loosing much kinetic energy, the projectile is always near the ground. The direction of the projectile will usually be close to the aim point.
There are tales of 18th and 19th century naval gunners intentionally "skipping" the cannon ball across the water to make a hit near the enemy ship's water line. If true, I suspect the range was 50 - 100 yards, and a miracle considering the ship was rolling with the wind and waves, and requiring exquisite timing. I suspect more likely the gunner got lucky and saw the ball splash in the water and hit the enemy ship's hull. Like many shooters, claimed that was the plan all along!