Instances evaluate to random integers in selected range
| 228 | |
| 229 | |
| 230 | class RandNum(_RandNumeral[int]): |
| 231 | """Instances evaluate to random integers in selected range""" |
| 232 | min = 0 |
| 233 | max = 0 |
| 234 | |
| 235 | def __init__(self, min, max): |
| 236 | # type: (int, int) -> None |
| 237 | self.min = min |
| 238 | self.max = max |
| 239 | |
| 240 | def _command_args(self): |
| 241 | # type: () -> str |
| 242 | if self.__class__.__name__ == 'RandNum': |
| 243 | return "min=%r, max=%r" % (self.min, self.max) |
| 244 | return super(RandNum, self)._command_args() |
| 245 | |
| 246 | def _fix(self): |
| 247 | # type: () -> int |
| 248 | return random.randrange(self.min, self.max + 1) |
| 249 | |
| 250 | def __lshift__(self, other): |
| 251 | # type: (int) -> int |
| 252 | return self._fix() << other |
| 253 | |
| 254 | def __rshift__(self, other): |
| 255 | # type: (int) -> int |
| 256 | return self._fix() >> other |
| 257 | |
| 258 | def __and__(self, other): |
| 259 | # type: (int) -> int |
| 260 | return self._fix() & other |
| 261 | |
| 262 | def __rand__(self, other): |
| 263 | # type: (int) -> int |
| 264 | return other & self._fix() |
| 265 | |
| 266 | def __or__(self, other): |
| 267 | # type: (int) -> int |
| 268 | return self._fix() | other |
| 269 | |
| 270 | def __ror__(self, other): |
| 271 | # type: (int) -> int |
| 272 | return other | self._fix() |
| 273 | |
| 274 | |
| 275 | class RandFloat(_RandNumeral[float]): |
no outgoing calls
no test coverage detected