Using Random Generated Global Variable As Temp User Code For Lock

I've been in a bit of slump trying to sort this one out. I would like to create a random temporary user password for guests that will be deleted after 1 use. I'm already having issues with using a global variable to set as a code. The lock being used is a Kwikset Smart Code 910 using setCode(Number (Position), String (Code) , String (Name)). The code works if I manually enter a number however once I replace that with my global variable it doesn't seem to like it. Any thoughts would be appreciated!