As always, one's own stack overflow answers make the best blog posts. In this case, we craft a version of random.Random with a few modifications: Pulls its data from an arbitrary stream (in our case, a DRBG such as a hash function or deterministic CSPRNG) Wastes noticeably fewer bits when generating random integers Has fixed code for .shuffle, on the offchance CPython ever changes theirs, and to make it …
Python: Rounding fractions half-up
By default, Python's fractions
rounds halves to the nearest even number. If you, instead, want to round a fraction but send halves up, here's how that's done:
def roundhalfup(x: Fraction) -> int:
"""
Rounds x to the nearest integer, with ties being rounded towards positive infinity
"""
return floor(x + Fraction(1, 2))
Javascript: Parsing query parameters
There are at least 2×5×7×3×3×1=630 different things you might unambiguously mean by "parsing" a query string in Javascript: …