Random codes in python