prettier
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
export default function getRandomItems<T>(items: T[], count: number): T[] {
|
||||
const shuffled = [...items];
|
||||
const shuffled = [...items];
|
||||
|
||||
// Fisher-Yates shuffle
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||
}
|
||||
// Fisher-Yates shuffle
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||
}
|
||||
|
||||
return count > shuffled.length ? shuffled : shuffled.slice(0, count);
|
||||
}
|
||||
return count > shuffled.length ? shuffled : shuffled.slice(0, count);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import getRandomItems from '@/tools/getRandomItems';
|
||||
|
||||
const alphabet =
|
||||
'0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
const alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
const generateID = (length: number = 6) => {
|
||||
return getRandomItems(alphabet.split(''), length).join('');
|
||||
return getRandomItems(alphabet.split(''), length).join('');
|
||||
};
|
||||
|
||||
export default generateID;
|
||||
|
||||
Reference in New Issue
Block a user