mirror of
https://github.com/Instadapp/assembly.git
synced 2024-07-29 22:37:06 +00:00
21 lines
565 B
TypeScript
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 };
|
||
|
}
|