original_string: public function generate($random = null) {
  		$results = [];
  
  		$plaintext = $this->_convert($random ?: $this->_random(8));
  		// String is already normalized by used alphabet.
  
  		$part = $try = 0;
  		while (count($results) < $this->_parts) {
  			$result = substr($plaintext, $try * $this->_partLength, $this->_partLength - 1);
  
  			if (!$result || strlen($result) !== $this->_partLength - 1) {
  				throw new Exception('Ran out of plaintext.');
  			}
  			$result .= $this->_checkdigitAlg1($part + 1, $result);
  
  			$try++;
  			if ($this->_isBadWord($result) || $this->_isValidWhenSwapped($result)) {
  				continue;
  			}
  			$part++;
  
  			$results[] = $result;
  		}
  		return implode('-', $results);
  	}
code: public function generate($random = null) {
  		$results = [];
  
  		$plaintext = $this->_convert($random ?: $this->_random(8));
  		// String is already normalized by used alphabet.
  
  		$part = $try = 0;
  		while (count($results) < $this->_parts) {
  			$result = substr($plaintext, $try * $this->_partLength, $this->_partLength - 1);
  
  			if (!$result || strlen($result) !== $this->_partLength - 1) {
  				throw new Exception('Ran out of plaintext.');
  			}
  			$result .= $this->_checkdigitAlg1($part + 1, $result);
  
  			$try++;
  			if ($this->_isBadWord($result) || $this->_isValidWhenSwapped($result)) {
  				continue;
  			}
  			$part++;
  
  			$results[] = $result;
  		}
  		return implode('-', $results);
  	}
code_tokens: public function generate ( $ random = null ) { $ results = [ ] ; $ plaintext = $ this -> _convert ( $ random ? : $ this -> _random ( 8 ) ) ; // String is already normalized by used alphabet. $ part = $ try = 0 ; while ( count ( $ results ) < $ this -> _parts ) { $ result = substr ( $ plaintext , $ try * $ this -> _partLength , $ this -> _partLength - 1 ) ; if ( ! $ result || strlen ( $ result ) !== $ this -> _partLength - 1 ) { throw new Exception ( 'Ran out of plaintext.' ) ; } $ result .= $ this -> _checkdigitAlg1 ( $ part + 1 , $ result ) ; $ try ++ ; if ( $ this -> _isBadWord ( $ result ) || $ this -> _isValidWhenSwapped ( $ result ) ) { continue ; } $ part ++ ; $ results [ ] = $ result ; } return implode ( '-' , $ results ) ; }
docstring: Generates a coupon code using the format `XXXX-XXXX-XXXX`.
  
  The 4th character of each part is a checkdigit.
  
  Not all letters and numbers are used, so if a person enters the letter 'O' we
  can automatically correct it to the digit '0' (similarly for I => 1, S => 5, Z
  => 2).
  
  The code generation algorithm avoids 'undesirable' codes. For example any code
  in which transposed characters happen to result in a valid checkdigit will be
  skipped.  Any generated part which happens to spell an 'inappropriate' 4-letter
  word (e.g.: 'P00P') will also be skipped.
  
  @param string $random Allows to directly support a plaintext i.e. for testing.
  @return string Dash separated and normalized code.
docstring_tokens: Generates a coupon code using the format XXXX - XXXX - XXXX .