I have an array of things (conceptually a set, but let's implement as an array), say [A, B, C, D, E, F].
I need an algorithm that can pseudo-randomly pick an item from the array such that no item will be picked twice within x iterations.
That is, if x is 3 for this array, this would be ok: F, C, B, D, F, E, A, B,...
This would not be ok: F, C, D, C, ...
Other than this constraint, the selections should be as random as possible. (For instance, simply shuffling the array and selecting within copies of it is not acceptable.)
Ideally, this would achieved without having to record all the previous picks.
So the function would have a structure like:
function pick(options, minspacing, iteration) {...}
(It will be implemented in JavaScript).
Aucun commentaire:
Enregistrer un commentaire