Implemented GenerateLastDigit function