I am looking to generate one specific arrangement of an array of items, given the items, and some identifier for which arrangement to generate. This should be deterministic (not random).
For example, for three items, there are 6 arrangements. Each time the user visits our site, we want them to see one specific arrangement, chosen based on what they saw last time. ("I saw order #1 ['a', 'b', 'c']
last time, so this time, show me order #2, which is ['a', 'c', 'b']
")
const items = ['a', 'b', 'c'];
const possibleArrangements = [
['a', 'b', 'c'],
['a', 'c', 'b'],
['b', 'a', 'c'],
['b', 'c', 'a'],
['c', 'a', 'b'],
['c', 'b', 'a'],
];
There are many ways to generate the entire list of possibilities by brute force, but generating every possible permutation seems overkill for this use case, when all we really need is to get one desired arrangement based on an identifier. Given the same items and the same identifier, I'm looking for a way to generate the same permutation every time, and only that arrangement.
magicFunction(['a', 'b', 'c'], 2)
>> ['b', 'a', 'c']
Suggestions would be welcome; thanks!