which we live can be accurately modeled only as stochastic processes process is stochastic if its next state depends upon both previous states and some random element stochastic programs program is deterministic if whenever it is run on the same inputit produces the same output notice that this is not the same as saying that the output is completely defined by the specification of the problem considerfor examplethe specification of squarerootdef squareroot(xepsilon)"""assumes and epsilon are of type floatx > and epsilon returns float such that -epsilon < * < +epsilon""this specification admits many possible return values for the function call squareroot( howeverthe successive approximation algorithm we looked at in will always return the same value the specification doesn' require that the implementation be deterministicbut it does allow deterministic implementations not all interesting specifications can be met by deterministic implementations considerfor exampleimplementing program to play dice gamesay backgammon or craps somewhere in the program there may be function that simulates fair roll of single six-sided die suppose it had specification something like def rolldie()"""returns an int between and ""this would be problematicsince it allows the implementation to return the same number each time it is calledwhich would make for pretty boring game it would be better to specify that rolldie "returns randomly chosen int between and most programming languagesincluding pythoninclude simple ways to write programs that use randomness the code in figure uses one of several useful functions found in the imported python standard library module random the function random choice takes non-empty sequence as its argument and returns randomly chosen member of that sequence almost all of the functions in random are built using the function random randomwhich generates random floating point number between and the word stems from the greek word stokhastikoswhich means something like "capable of divining stochastic programas we shall seeis aimed at getting good resultbut the exact results are not guaranteed roll is fair if each of the six possible outcomes is equally likely in point of factthe function is not truly random it is what mathematicians call pseudorandom for almost all practical purposes outside of cryptographythis distinction is not relevant and we shall ignore it