<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def digit(self, to_bin: bool = False) -> Union[str, int]: """Get a random digit. :param to_bin: If True then convert to binary. :return: Digit. :Example: 4. """

        digit = self.random.randint(0, 9)

        if to_bin:
            return bin(digit)

        return digit