Why does it need to be encoded? If it needs to be encoded then have a look in the manual.
I think what you might need is some kind of randomisation script? Are you using a database, if so could you not just use a field with an auto increment as the id?