The initial mass function (IMF) for stars is proposed to result from two distinct physical processes that determine its shape separately in two intervals of mass: random sampling of mass in a fractal cloud gives the power-law portion at intermediate to high mass, and insufficient self-gravity at the local temperature and pressure gives the cutoff at low mass. The entire function is modeled numerically, with the assumption that a star's mass is proportional to the mass of the piece of cloud in which it forms. The results typically give an IMF with the Salpeter value for the slope and a flattening at a low mass. There is little sensitivity to parameters at masses greater than the cutoff, although slightly shallower IMFs might be expected in regions with high levels of ionization and turbulence. The low-mass cutoff is essentially the thermal Jeans mass in the star-forming cloud; models with a high value of this mass produce a truncated IMF similar to that proposed for starburst galaxies. The mass of the largest star increases with total stellar mass because of the stochastic nature of the model. The star IMF is steeper than the cloud mass spectrum because of competition for mass and the density dependence of star formation.