In nature ants will search for food more or less randomly, but collectively their foraging is still efficient. Ants can communicate with each other by releasing pheromones. When an ant happens to find a food source the ant will lay out a trail of pheromones as it returns to the colony. If other ants finds this trail they will follow it to the food source, and when they return to the colony they will also lay out a pheromone trail thereby strengthening the existing trail. In this way information about food sources can spread and lead to effecient use of the food sources. When a particular food source has been depleted there will be no more ants reinforcing that pheromone trail when returning with food. When the trail is no longer being reinforced it will eventually disappear.
In the java simulation below the ants are represented by purple dots, while food sources are shown in dark blue. The two sliders regulate the number of ants in the simulation and the dissipation rate of the pheromones. With the default settings the ants will have exhaused all of the food sources in the simulation after a couple of minutes.
Simulations of this kind are closely related to Ant Colony Optimization (ACO) algorithms, although the purpose here is not really optimization.