Sorry, my code should have: val r : word ref = ref 0wx0 There's no need to call rand () before the first call to alphaNumChar, as the count is already set for a refresh. (Plus, we'll save dozens of precious nanoseconds ;-)