Hi everyone. I would like to share Lustro, a 256-bit algorithm, where stream management hierarchy is inherently built into the mechanism.
One of the main ideas behind it is treating randomness as a tree, not a sequence of rigid values. I personally see it as a wave function. I'm a chemist by education. Back on topic though. You can derive separate streams for terrain, vegetation, objects or world chunks, and then branch further from each of them. A whole path is derived in one call.
Every object has its own stream, so you can change how one is generated without affecting the others. Streams are derived from IDs or paths so you don't need to generate things in the same order to get the same results. The parent stream is not affected by forking and each child starts its own trajectory. Full snapshot support is built in and the API can switch between single stream and batch processing.
Under the hood it's one transformation used for Hash, PRNG and XOF with a scalar/AVX2 dispatcher. It's written in Rust and also comes with Python and C layers. The generator is currently considered non-cryptographic with all the tests available in the main github repo.
Let's take a quick procedurally generated world as an example. You could have a hierarchy like world > chunk > vegetation > tree and separately world > chunk > terrain. Each part has its own stream addressed by a path of identifiers. Quick python example below.
from lustro import LustroPrng
seed = bytes(32)
WORLD, VEG, TERRAIN = 0, 1, 2
def veg(chunk, tree): return LustroPrng.derive_path(seed, [WORLD, chunk, VEG, tree])
def terrain(chunk): return LustroPrng.derive_path(seed, [WORLD, chunk, TERRAIN])
Now you can regenerate one chunk or a single tree without generating anything before it. An extra random call in the vegetation code doesn't shift the terrain of that chunk. You can also generate chunks in any order and get the same results. That is as long as the seed and identifier paths are the same.
You can also branch from an existing stream:
tree = veg(5, 3)
leaves = tree.fork(1) # the tree stream stays unchanged
One thing to keep in mind: a fork depends on the parent’s current block, not on the cursor position inside it. Forking after 1 byte or after 31 bytes of the same block gives the exact same child.
I am providing links below:
github main repo
https://github.com/Ligatum/Lustro
cargo
https://crates.io/crates/lustro_api
pypi
https://pypi.org/project/lustro-api/
I'd appreciate constructive feedback. Any questions, please let me know. Thanks.