The dimples on a golf ball are in place to enhance an effect known as "Magnus lift," which causes objects flying through a fluid (such as air or water) to lift up if they are spinning. The dimples caused backspin on the golf ball when it is hit with a club. A smooth ball won't travel as high into the air, meaning it won't travel as far as a dimpled ball. Due to the Magnus lift effect, a dimpled golf ball can actually travel further in air than it would in a vacuum, at least at realistic low angles of strike. (1)
This graph shows how the height at which a golf ball travels affects its travel distance:
By Dantor (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0) or GFDL (http://www.gnu.org/copyleft/fdl.html)], via Wikimedia Commons
A regulation golf ball does not have a specific number of dimples, but it will be between 300 and 500 dimples. Most balls have 336 dimples. The exact number of dimples is not random, however, as it is vital that the dimples are arranged symmetrically. Some numbers of dimples just can't be arranged evenly and result in a ball that won't fly straight (2).
This image shows a potential symmetrical arrangement of golf ball dimples: