Skip to content
  • Privacy Policy
「 ishygddt.xyz/~blog/ 」
  • Privacy Policy
「 ishygddt.xyz/~blog/ 」

Tag: math

Most efficient random integer generator by random bits consumed

February 23, 2022March 26, 2022

Discovered in 2013 by then-UPMC-student Jérémie Lumbroso, and independently re-discovered by an Apple programmer last Fall (with much ado on Twitter and Hacker News), the basic idea is as follows: Take your (infinite) random bitstream as the binary digits of random $r\in\left[0,1\right)$…

Posted in Writeups  •  No Comments on Most efficient random integer generator by random bits consumed

Python: Rounding fractions half-up

June 25, 2021March 8, 2022

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))
Posted in Writeups  •  No Comments on Python: Rounding fractions half-up

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Referral Links 💵

  • VPS ($5/mo 2-core, 2GB RAM, 80GB SSD)
  • Cheap Chinese Electronics
  • Custom Bankcard Covers
  • Disposable Virtual Debit Cards
  • Brokerage

Recent Posts

  • [DRAFT] Data structure simple hex grid for Catan
  • tk.messagebox is ugly on Linux
  • Outlook Web Access S/MIME user installation
  • Using "pip" behind a corporate firewall
  • Can't install Twine on PyPy due to nh3 "Rust" problem

Recent Comments

  • Rocky Linux 9 & HP Elitebook 8470p: Wi-Fi problems reconciled – 「 ishygddt.xyz/~blog/ 」 on Rocky Linux 9 & HP Elitebook 8470p: GPU problems irreconciled
  • Rocky Linux 9 & HP Elitebook 8470p: GPU problems irreconciled – 「 ishygddt.xyz/~blog/ 」 on Rocky Linux 9 & HP Elitebook 8470p: Wi-Fi problems reconciled
  • Author on the real frozendict was the standard library we neglected along the way
  • Author on A very tiny bitmap font
  • Author on X25519 original specification

Archives

  • August 2024
  • April 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • January 2023
  • October 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • August 2020
  • July 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • August 2019

Categories

  • [DRAFT]
  • How-To
  • OC
  • Transcripts
  • Uncategorized
  • Writeups

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Copyright © 2025 「 ishygddt.xyz/~blog/ 」 — powered by Suki