I don't think 'random' can take a negative value. By saying random(0-639) you're not saying between 0 and 639, you are literally saying zero subtract 639, which is random(-639), which probably isn't doing what you want it to. random(640) goes between 0 and 639 inclusive, which is probably what you want.