mercredi 19 mai 2021

Generator for iterating over a random non-repeated sequence

I have p items (let's assume p=5, items={0,1,2,3,4}). I need to be able to iterate over them in a random order, but without repeating them (unless all were visited) while maintaining only as small seed-like metadata as possible between the iterations. The generator is otherwise stateless. It would be used like this:

Initialization (metadata is long in this example, but it could be anything "small"):

long metadata = randomLong()

Usage:

(metadata, result) = generator.generate(metadata)
return(result)

If it works properly, it should continuously return something like 3, 1, 0, 4, 2, 3, 1, 0, 4, 2, 3...

Is that possible?

I know I could easily pre-generate the sequence, then metadata would contain whole this sequence and an index, but that's not viable for me, as the sequence will have thousands of items and the metadata must be slim.

I also found this, which resembles what I am trying to achieve, but it's either too brief or too math-y for me.




Aucun commentaire:

Enregistrer un commentaire