Skip to content

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

@Mertz22

Description

@Mertz22

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 ethers-io/ethers.js#324 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions