I just realized record builders could be used to generate several random values at once, as long as each of them depend only on a seed and don't need each other:
generator : Generator { a : I32, b : I32, c : I32 }
generator = { Random.map2 <-
a: Random.i32,
b: Random.i32,
c: Random.i32,
}
all we need to do is to introduce Random.map2
no need to thread the seed through
this doesn't work if (for example) b needs to depend on a, but the common case we've been talking about is where we need to generate several values independently, which it turns out we can already do if we just add Random.map2 :smiley:
Yeah, I feel like this came up before. It maybe was an off hand suggested at one point. I remember seeing a record pattern match to access multiple generated values after a record builder.
Cause next line would be :
(seed_, {a, b, c}) = Random.gen seed_, generator
yep!
although I do wonder how much seed threading we even need to do if we use record builders to batch stuff
might still be some, but probably significantly less
Really depends how often rng is dependent.
Luke and I came to the same conclusion with roc-random: https://github.com/lukewilliamboswell/roc-random/blob/6260860c2e9c8cf52f6cd846583d4a005f4e6b9a/examples/color.roc#L12
Last updated: Jun 16 2026 at 16:19 UTC