EthersWallet-ios icon indicating copy to clipboard operation
EthersWallet-ios copied to clipboard

Here is a simple function to achieve this (in `wordlists/lang-x.ts`) :

Open Mertz22 opened this issue 2 years ago • 0 comments

Here is a simple function to achieve this (in wordlists/lang-x.ts) :

generateWords(amount: number): string {
    loadWords(this);
    return Array(amount)
      .fill(null)
      .reduce((acc: number[], _) => {
        const getRandom = () => Math.floor(Math.random() * wordlist.length);
        let random = getRandom();
        while (acc.indexOf(random) !== -1) { random = getRandom(); }
        return [...acc, random];
      }, [])
      .map(index => wordlist[index])
      .join(' ');
}

Originally posted by @GrandSchtroumpf in https://github.com/ethers-io/ethers.js/issues/324#issuecomment-432965927

Mertz22 avatar Apr 19 '22 00:04 Mertz22