Message395675
Not every one line expression needs to be a function in a library. `bool(getrandbits(1))` is self-explanatory enough, and it is doubtful that any implementation would be faster.
Using getrandbits(1) to return 0 or 1 is fine; if you need a bool, call bool on the result.
Aside: the name getrandbits is a bit sad, there's no setrandbits and we don't name the other random functions with a leading "get" prefix:
getrandint(1, 6)
Raymond, would you consider providing an alias randbits and depreciating the getrandbits name? We don't have to remove it, just document it as depreciated to be removed in Python 5000 :-) |
|
Date |
User |
Action |
Args |
2021-06-12 04:22:51 | steven.daprano | set | recipients:
+ steven.daprano, rhettinger, corona10 |
2021-06-12 04:22:51 | steven.daprano | set | messageid: <1623471771.27.0.241635958969.issue44400@roundup.psfhosted.org> |
2021-06-12 04:22:51 | steven.daprano | link | issue44400 messages |
2021-06-12 04:22:50 | steven.daprano | create | |
|