Token generation function