ethers-io / EthersWallet-ios

Ethereum Wallet and Dapp Browser for iOS.
https://itunes.apple.com/us/app/ethers-wallet/id1186052971?mt=8
MIT License
303 stars 85 forks source link

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

Open Mertz22 opened 2 years ago

Mertz22 commented 2 years ago

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