frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

If you're doing Monte Carlo try Knuth LGC

4•logicallee•18h ago
I was doing a monte carlo simulation involving a few million iterations and that didn't really need anything all that random. I remembered reading about a fast algorithm for very fast values (just a couple of ops), so I asked about this and was surprised that there is one. I just inserted it into my c code and it became ten times faster. If you're doing some monte carlo simulations where you don't need anything very random, give it a try.

before: 3.5 seconds. after: 0.42 seconds.

code I used:

   #include <stdint.h>

   static uint32_t seed = 1;   // any non-zero value is fine

   static inline uint32_t fast_rand(void) {
       seed = seed * 1664525u + 1013904223u;   // mod 2^32 is free
       return seed;
   }

   // then (example):
   int ch = fast_rand() % 1297 // where 1297 is the range.

(there's a slight bias when using % this way.) code gave the same results so it was still correct. you would adjust 1297 to the range you need an integer result in, this is from my example.

Ask HN: Anthropic is accusing my company of distilling. How can I prove I'm not?

477•weli•4d ago•362 comments

Tell HN: Happy Thanksgiving

722•ericmay•2d ago•157 comments

Tell HN: Lots of Ask HNs again

411•dang•2d ago•155 comments

Ask HN: Who is still worried about copyright issues with AI generated code?

3•sonjaqql•7h ago•4 comments

Tell HN: 0 Purchases This Thanks Giving

4•prakashn27•7h ago•3 comments

Which city do you live in?

3•Eyyup•8h ago•3 comments

Ask HN: Is anyone using Gemini Live (3.8) in scaled production

3•aenis•8h ago•0 comments

Ask HN: Has AI started impacting hiring in your org?

6•ChaitanyaSai•14h ago•0 comments

Ask HN: Where is all the amazing AI-generated software?

27•8bitbeep•3d ago•63 comments

I was hired by an AI agent

12•dev_chad•22h ago•13 comments

Ask HN: Is RSA in Jeopardy?

21•lyfeninja•3d ago•14 comments

DietPi released a new version v10.9

21•stephanstsdietp•2d ago•3 comments

Ask HN: Any courses/products by indie makers worth getting today?

82•akudha•2d ago•41 comments

If you're doing Monte Carlo try Knuth LGC

4•logicallee•18h ago•0 comments

Ask HN: YC startup not paying for a take-home. What to do?

12•unpaidtakehome•19h ago•11 comments

Ask HN: Users asking to remove their commits under GDPR

8•punkpeye•1d ago•5 comments

Ask HN: Coworker rejects PR (a month in) because it does not meet his standards

23•LandOfMightDev•4d ago•46 comments

Ask HN: How do you find meaning of life at 41?

71•BTA_DoIt•2d ago•122 comments

Ask HN: How well do you understand what's going on inside RL?

9•natsu529•1d ago•5 comments

Ask HN: Will GPTs Get Stupider?

2•dfps•1d ago•2 comments

Ask HN: Am I the only one whose AI hype is cooling down a lot?

38•redleathercouch•4d ago•28 comments

Ask HN: How do you handle corporate life?

6•busssard•2d ago•7 comments

Ask HN: What's Going on with the Minecraft Rust Rewrite? (Horizon)

6•goodmythical•1d ago•7 comments

Ask HN: Would you care for more than 2FA for any of your accounts?

3•sandeepkd•1d ago•8 comments

Ask HN: Why can AI prove Riemann but not solve cust svc problems?

2•louiereederson•1d ago•8 comments

Ask HN: Security for the Small Developer

12•dvduval•2d ago•9 comments

Ask HN: Its 2026 and there is still not good Email client for macOS. Why?

13•orbanlevi•4d ago•23 comments

Ask HN: Everything will get breached. How do you limit the blast radius?

20•humbleferret•4d ago•16 comments

Ask HN: If you had no limitations what would you build in AI?

11•NarcisMirandes•3d ago•35 comments

Why are so many services using email magic links for login?

20•bfbf•4d ago•20 comments