frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Efficiently Generating a Number in a Range (2018)

https://www.pcg-random.org/posts/bounded-rands.html
50•csense•6mo ago

Comments

cbarrick•6mo ago
https://archive.ph/oeZQw
eru•6mo ago
Python (or more precisely CPython) uses something like a bitmask and rejection. Alas, there's a bug in the code, so that when you generate a range whose size is a power of two, instead of getting the best case (no rejections), you get half of your values rejected.

For clarity, this worst case for this approach should happen for ranges with size 2*x+1, ie one more than a power of two.

The bug is known but not being fixed right now to keep random number output consistent.

dspillett•6mo ago
> Back when I was a student writing homework assignments rolling dice or drawing cards, no one really worried about these tiny biases,

That brings back an old (> 3 decades) memory… Way back when, not actually part of a homework assignment but a time in my life I would get them, I noticed a bias while picking random cards. This IIRC was with a 16 (or maybe even 8) bit PRNG, I'm not sure if the significance of the bias was due to that or just if the PRNG overall was terrible. After doing some simple analysis to prove some cards were less likely to be picked, my answer was to actually shuffle the deck: move the cards around in an array, looping over the whole array picking a new position for each card, multiple times. Of course it was slow so would not fit in with the "efficient" goal of this article, but it did seem to smooth out the bias, and picking in order from a pre shuffled deck much better emulated the real world game I was trying to implement at the time (so why wasn't I doing that from the offset?: the bad design process of a early-teens self-taught fledgeling programmer!).

The analysis (written almost entirely in BASIC though the shuffle was in 6502 assembly as I was learning that a bit at the time) was my first experience of running a programmed process over several hours, my parents were dubious about the good ol' BBC Master needing to be left powered on all night! The results may have been completely wrong but (very) young me was convinced at the time. Ahh, innocent times…

stevan•6mo ago
This post https://jacquesheunis.com/post/bounded-random/ from 2021 contains some newer techniques.
kwillets•6mo ago
Extended-width multiplication works, but the cost of extra random bits is often a lot higher than the range arithmetic.

Somewhere in my github there's an indefinite-width multiply that only adds bits while there's a risk of carry into the 1's digit; the check for that is quite cheap.

zokier•6mo ago
The bitmask approach is the clear winner in my books. It is just so simple and easy to understand while also having decent perf. It is kinda surprising that apparently those slower and (imho) more difficult to understand solutions are in use anywhere.

I wonder what is the best real-time (fixed latency) approach for unbiased ranges?

Brookhaven Lab's RHIC concludes 25-year run with final collisions

https://www.hpcwire.com/off-the-wire/brookhaven-labs-rhic-concludes-25-year-run-with-final-collis...
20•gnufx•2h ago•8 comments

SectorC: A C Compiler in 512 bytes

https://xorvoid.com/sectorc.html
61•valyala•3h ago•12 comments

I write games in C (yes, C)

https://jonathanwhiting.com/writing/blog/games_in_c/
105•valyala•3h ago•81 comments

Speed up responses with fast mode

https://code.claude.com/docs/en/fast-mode
36•surprisetalk•3h ago•43 comments

Software factories and the agentic moment

https://factory.strongdm.ai/
75•mellosouls•6h ago•147 comments

Hoot: Scheme on WebAssembly

https://www.spritely.institute/hoot/
138•AlexeyBrin•8h ago•26 comments

Stories from 25 Years of Software Development

https://susam.net/twenty-five-years-of-computing.html
86•vinhnx•6h ago•11 comments

OpenCiv3: Open-source, cross-platform reimagining of Civilization III

https://openciv3.org/
846•klaussilveira•23h ago•253 comments

First Proof

https://arxiv.org/abs/2602.05192
60•samasblack•5h ago•49 comments

The F Word

http://muratbuffalo.blogspot.com/2026/02/friction.html
14•zdw•3d ago•0 comments

The Waymo World Model

https://waymo.com/blog/2026/02/the-waymo-world-model-a-new-frontier-for-autonomous-driving-simula...
1080•xnx•1d ago•615 comments

Al Lowe on model trains, funny deaths and working with Disney

https://spillhistorie.no/2026/02/06/interview-with-sierra-veteran-al-lowe/
59•thelok•5h ago•8 comments

Reinforcement Learning from Human Feedback

https://rlhfbook.com/
88•onurkanbkrc•8h ago•5 comments

Start all of your commands with a comma (2009)

https://rhodesmill.org/brandon/2009/commands-with-comma/
509•theblazehen•3d ago•188 comments

Vocal Guide – belt sing without killing yourself

https://jesperordrup.github.io/vocal-guide/
226•jesperordrup•13h ago•80 comments

Microsoft account bugs locked me out of Notepad – Are thin clients ruining PCs?

https://www.windowscentral.com/microsoft/windows-11/windows-locked-me-out-of-notepad-is-the-thin-...
34•josephcsible•1h ago•26 comments

We mourn our craft

https://nolanlawson.com/2026/02/07/we-mourn-our-craft/
298•ColinWright•2h ago•353 comments

Show HN: I saw this cool navigation reveal, so I made a simple HTML+CSS version

https://github.com/Momciloo/fun-with-clip-path
21•momciloo•3h ago•2 comments

Coding agents have replaced every framework I used

https://blog.alaindichiappari.dev/p/software-engineering-is-back
246•alainrk•8h ago•393 comments

72M Points of Interest

https://tech.marksblogg.com/overture-places-pois.html
34•marklit•5d ago•6 comments

France's homegrown open source online office suite

https://github.com/suitenumerique
601•nar001•7h ago•264 comments

Selection Rather Than Prediction

https://voratiq.com/blog/selection-rather-than-prediction/
11•languid-photic•3d ago•4 comments

The AI boom is causing shortages everywhere else

https://www.washingtonpost.com/technology/2026/02/07/ai-spending-economy-shortages/
172•1vuio0pswjnm7•9h ago•233 comments

A Fresh Look at IBM 3270 Information Display System

https://www.rs-online.com/designspark/a-fresh-look-at-ibm-3270-information-display-system
43•rbanffy•4d ago•9 comments

Unseen Footage of Atari Battlezone Arcade Cabinet Production

https://arcadeblogger.com/2026/02/02/unseen-footage-of-atari-battlezone-cabinet-production/
121•videotopia•4d ago•36 comments

History and Timeline of the Proco Rat Pedal (2021)

https://web.archive.org/web/20211030011207/https://thejhsshow.com/articles/history-and-timeline-o...
20•brudgers•5d ago•4 comments

Show HN: Kappal – CLI to Run Docker Compose YML on Kubernetes for Local Dev

https://github.com/sandys/kappal
27•sandGorgon•2d ago•14 comments

Where did all the starships go?

https://www.datawrapper.de/blog/science-fiction-decline
89•speckx•4d ago•99 comments

Learning from context is harder than we thought

https://hy.tencent.com/research/100025?langVersion=en
207•limoce•4d ago•113 comments

Show HN: Look Ma, No Linux: Shell, App Installer, Vi, Cc on ESP32-S3 / BreezyBox

https://github.com/valdanylchuk/breezydemo
282•isitcontent•23h ago•38 comments