assembly/composables/useRandom.ts
Georges KABBOUCHI 5d00313260 wip
2021-07-25 02:40:30 +03:00

21 lines
565 B
TypeScript

export function useRandom() {
function makeid(length) {
let result = "";
const characters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
return { makeid, getRandomInt };
}