Why is my random shuffle always producing the same result when using Suiji?

Actually I just had one more idea that I’ll put separately; using callbacks:

#let rng = state("rng", (gen-rng(1), none))

#let randomize(options, callback) = {
  rng.update(((rng, _)) => shuffle(rng, options))
  context callback(rng.get().last())
}

#let options = ("A", "B", "C", "D")

#randomize(options, shuffled => [#shuffled])

#randomize(options, shuffled => [#shuffled])

This lets you make a single randomize call and hides the random handling, but it requires you to put everything that depends on the random result in a callback. This probably becomes annoying when you need multiple random things at the same time (meaning you have nested callbacks).

2 Likes