We introduce a class of utility of wealth functions, called knapsack utility functions, which are appropriate for agents who must choose an optimal collection of indivisible goods subject to a spending constraint. We investigate the concavity/convexity and regularity properties of these functions. We find that convexity–and thus a demand for gambling–is the norm, but that the incentive to gamble is more pronounced at low wealth levels. We consider an intertemporal version of the problem in which the agent faces a credit constraint. We find that the agent’s utility of wealth function closely resembles a knapsack utility function when the agent’s saving rate is low.