fix: random movie index preservation
This commit is contained in:
1 parent
9dc731299f
commit
9e4e1d62fd
7 files changed
+78
-74
No files matched your search
@@ -15,3 +15,21 @@ export const mapFilters = (filters: Record<string, string>) => {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export const createUniqueRandomGenerator = (max: number) => {
|
||||
const numbers = Array.from({ length: max }, (_, i) => i + 1);
|
||||
|
||||
for (let i = numbers.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[numbers[i], numbers[j]] = [numbers[j], numbers[i]];
|
||||
}
|
||||
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
if (index >= numbers.length) {
|
||||
index = 0;
|
||||
}
|
||||
return numbers[index++];
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user