Skip to content

alternative shuffle #2

@pauldreik

Description

@pauldreik

idea: is it possible to shuffle with something else than fisher yates? think about how to get rid of that division.

one way is to generate an index vector the same size as the elements, fill it with a random permutation (for instance by encrypting a counter, like i do in the random foreach repository).
then the vector can be resized by looping over the data, putting the data where it belongs, one at a time. it the element swapped with is not in the right position, put it there. eventually one can proceed with the next position.

could one use std::sort, but with a comparator that hashes the elements before comparing them? one problem is that the order between equivalent elements will not be the same, but that could perhaps be fixed in a second pass over the elements, where all equal ranges are shuffled with some other algorithm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions