A model of cooperation versus defection in a sequence of games is analysed under the assumptions that the rules of the game are randomly changed from one encounter to another, that the decisions are to be made each time anew, according to the (random) rules of the specific local game, and that the result of one such game affects the ability of a player to participate and thus, cooperate in the next game. Under plausible assumptions, it is shown that all Nash solutions of the supergame determine cooperation over a non-degenerate range of rules, determining encounters of the prisoner's dilemma type.