there are two components to your algorithm. the first component is (as gene pointed out) is to generate a random number. the second component is to verify the violations for the generated integers. the violation verfication is a function of two things: the previous sequence of numbers and the set of input rules you choose.