Professional Documents
Culture Documents
Deletar 3
Deletar 3
Deletar 3
Note: The include syntax is temporary in order to provide legacy support. In the
upcoming update it is going to change.
HTML
<script src="https://raw.githubusercontent.com/Rafal-Majewski/random-text-
generator-js/master/random_text_generator_browser.js"></script>
node.js
npm install random-text-generator
const RandomTextGenerator=require("random-text-generator");
Getting Started
All the values shown in settings are the default values.
// You can change the settings on the fly as well, just write
randomTextGenerator.settingName=newValue.
let settings={
tries: 80, // That many times the generator will try to generate. If exceeded
the generator returns null.
safeMode: true, // Safe mode makes the generation process faster, but makes
the output a bit worse.
forceCombiningOrigins: false, // Force the generator to combine origins. See
examples for details on origins.
minLength: 1, // Minimal length (inclusive) of output.
maxLength: 400, // Maximal length (inclusive) of output.
deepness: 40, // That many previous characters are used while determining a
new character. The greater the generator is more intelligent, but needs more
memory.
trust: 2, // That many times a substring of characters must occur in order to
be used while generating.
weightsLeft: {} // Startings weights for generating right -> left.
weightsRight: {} // Startings weights for generating left -> right.
splitter: "", // A character that is use to split characters. Basically use
"" while generating words and " " while generating sentences.
startingCharacter: String.fromCharCode(2), // A character that every word
starts with. You don't include that in your input examples and it's not included in
the generated output.
endingCharacter: String.fromCharCode(3), // A character that every word ends
with. You don't include that word in your input examples and it's not included in
the generated output.
};
// Initialize an instance of the generator with custom settings
let randomTextGenerator=new RandomTextGenerator(settings);
// Or initialize it with the default settings
let randomTextGenerator=new RandomTextGenerator();
Examples
Usernames
const RandomTextGenerator=require("random-text-generator");
let
polishCities=["Warszawa","Kraków","Łódź","Wrocław","Poznań","Gdańsk","Szczecin","By
dgoszcz","Lublin","Białystok","Katowice","Gdynia","Częstochowa","Radom","Toruń","So
snowiec","Kielce,Rzeszów","Gliwice","Zabrze","Olsztyn","Bielsko-
Biała","Bytom","Zielona Góra","Rybnik","Ruda Śląska","Opole","Tychy","Gorzów
Wielkopolski","Płock","Dąbrowa
Górnicza","Elbląg","Wałbrzych","Włocławek","Tarnów","Chorzów","Koszalin","Kalisz"]
// Teach the generator the names of the cities, but preserve its origin.
for (let americanCity of americanCities) randomTextGenerator.learn(americanCity,
"americanCity");
for (let polishCity of polishCities) randomTextGenerator.learn(polishCity,
"polishCity");