A cryptographically secure Node.js random generator for real English words. Contains over 370,000 English words.

Built and maintained by Ptorx and other Xyfir Network projects.

Note: rword stores its words array in memory, and limited testing shows this to add about ~20-60 MB to Node's heap depending on which word list you choose. rword is built to be fast and self-contained without the need for a database and this price is paid at the expense of your RAM.

Examples

import { rword } from ' rword ' ; rword . generate ( ) ; rword . generate ( 5 ) ; rword . generate ( 5 , ) ; rword . generate ( 3 , ) ; rword . generate ( 5 , ) ; rword . generate ( 5 , ) ; rword . generate ( 5 , ) ; rword . generate ( 3 , ) ; rword . generate ( 3 , ) ; rword . generateFromPool ( 5 ) ;

Words

rword comes with two word lists: small , with a "tiny" ~129k words, and big , with ~370k. By default, rword uses small .

All of the words contain only a-z characters. There are no numbers, symbols, spaces, or diacritics.

small contains only words 3-10 characters in length, while big has no length requirements.

small is likely to decrease in size in the future, while big may increase.

API

Generates words from the global words array.

count: number - Optional (default 1 ) - How many words to return. If 1 or not present, a string is returned. If greater than 1 an array of strings is returned.

- Optional (default ) - How many words to return. If or not present, a string is returned. If greater than an array of strings is returned. options: object - Optional - Allows you to modify the output and words that could be randomly chosen.

- Optional - Allows you to modify the output and words that could be randomly chosen. options.length: number|string - Optional (default '3-10' ) - Allows you to set an exact length or range of lengths for words to return.

- Optional (default ) - Allows you to set an exact length or range of lengths for words to return. options.contains: string|RegExp - Optional (default /.*/ ) - Words that don't match the regexp will not be returned.

- Optional (default ) - Words that don't match the regexp will not be returned. options.capitalize: string - Optional (default 'none' ) - Changes the capitalization of the words returned. Possible values: 'none' | 'all' | 'first' .

It should be obvious, but be warned that there's no guarantee you'll receive as many words as requested if you use any of the filtering options. In addition, adding filters to is slow, and should be avoided if possible. Use rword.generateFromPool() if possible as it can be much faster, especially for generating a single word.

Generates words from the global pool array. The pool is automatically filled using rword.generate(500) and then words are taken out of that array as needed. Can be faster than rword.generate() for generating small amounts of words.

count: number - Optional (default 1 ) - How many words to return. If 1 or not present, a string is returned. If greater than 1 an array of strings is returned.

Limitations:

No options object is accepted.

You cannot request more than 10 words through this method.

Loads and shuffles word list. This is a blocking function that does a lot of processing, so don't call it often.

list: "big" | "small" - The list you'll load into rword. "small" is automatically loaded upon first importing rword.

Shuffles both the global and pool words arrays. This method can most likely be ignored as it is automatically called on first run.

The full (shuffled) words array that is used internally by rword. Likely there's no need for this but if you'd like to bypass the rword API and just utilize its words then this is what you'll need.