Skip to content

Instantly share code, notes, and snippets.

Some quick notes about PRNGs

If the docs don't specify the cycle length, IMHO better not use it in situations where it matters.

65**5 is about 30 bits. if the PRNG-state is 32 bits, and the PRNG algorithm doesn't cycle through the full state, that may already be too little.

In many languages the default PRNG is implemented as a LCG, which are just 2-3 lines of code, and just not very good on their own. Computational science has found much, much better algorithms that are (almost) just as tiny to implement. Maybe 4-5 lines, see PCG-random.org.

I recently used a Java port of CMWC4096 from StackOverflow, for a numerical simulation in Java (where the default Math.random() has a stupid-bad cycle length, and the Java crypto-PRNG might have been too slow). It worked great. Not quite as tiny as PCG-random, but still short and it was ready-to-use Java-code that fit my needs.

@tripzilch
tripzilch / mogelijk de beste vega chili ooit.md
Created April 18, 2017 19:11
mogelijk de beste chili ooit (vegetarisch)

Mogelijk de beste chili ooit (vegetarisch)

  • 2-3 medium uien, halve ringen
  • 3 dikke tenen knoflook, gesnipperd
  • 1 zoete aardappel (paarse schil), blokjes
  • 1 chilipeper, pitjes verwijderd, fijngesnipperd (2 was achteraf beter denk ik)
  • halve winterpeen, kleine blokjes / gesnipperd
  • genoeg olijfolie

in stevige grote pan aanbakken/fruiten tot het bruin begint te worden. ondertusen oven voorverwarmen. daarna toevoegen:

Pasta en champignon en crème fraiche en broccoli

Voor 2 personen.

  • 1 bakje champignons
  • 1 broccoli (of 2 kleintjes)
  • 2-3 uien, 3-4 dikke tenen knoflook
  • 1 bekertje creme fraiche
  • zonnebloempitjes (optioneel)
  • verse zwarte peper
@tripzilch
tripzilch / prng-xorshift128.js
Last active July 9, 2020 11:49
Seedable Xorshift128 PRNG
// RNG = Math.random
RNG = xorshift128
function nonsense() {
// if all you need
// is a random seed
// of type string
// then this thing
// does the deed, hey
xorshift128_seed(Date.now() + '');
@tripzilch
tripzilch / quadtree.js
Last active December 5, 2023 21:59 — forked from L-A/quadtree.js
Basic quadtree implementation in JS
const CAPACITY = 8;
class QuadTree {
constructor(x, y, w, h) {
// the rect (x,y,w,h) defines the product of two half-open intervals: [x, x+w) × [y, y+h)
this.x = x; this.xe = x + w;
this.y = y; this.ye = y + h;
this.w = w;
this.h = h;
this.pts = [];

001

Love the way the light shines through it like that

002

The General Prototype

003