fakeword

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: MIT Imports: 4 Imported by: 0

README

fakeword

Go Reference test Go Report Card

Go package fakeword allows to generate fake words.

Example

Adding some English words, will generate fake words that sound english.

Try the example online on pkg.go.dev.

package main

import "thde.io/fakeword"

func main() {
    words := []string{
        "Psychotomimetic",
        "Pulchritudinous",
        "Consanguineous",
        "Trichotillomania",
    }

    dict := fakeword.Dictionary{}
    dict.Add(words...)

    gen := dict.Generator()
    fmt.Println(gen.Word())
}

The library was inspired by nwtgck/go-fakelish.

Documentation

Overview

Package fakeword allows to generate fake words. Adding words of a certain language, allows to generate language like words.

Index

Examples

Constants

View Source
const (
	// MaxSequencesDefault contains the default for Generator.MaxSequences.
	MaxSequencesDefault = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Dictionary

type Dictionary struct {
	PrefixLength int
	// contains filtered or unexported fields
}

Dictionary stores words to be used to create a Generator.

func (*Dictionary) Add

func (w *Dictionary) Add(words ...string) *Dictionary

Add words to a Dictionary.

func (*Dictionary) Generator

func (w *Dictionary) Generator() Generator

Generator returns a new Generator based on the words added to the dictionary.

func (*Dictionary) Read

func (w *Dictionary) Read(in io.Reader) *Dictionary

Read from an io.Reader and adds those words to a Dictionary. Lines prefixed with # are skipped.

type Generator

type Generator struct {
	// Probabilities stores the probabilities of characters following on a string.
	Probabilities map[string]map[string]float32
	// MaxSequences defines how far back the algorithm looks
	// to predict the next character. A smaller value icreases randomness
	// and a higher value creates words that are closer to the dictionary words.
	// The default value is defined in MaxSequencesDefault.
	MaxSequences int

	// Random should return a 32-bit value as a uint32.
	// Uses math/rand/v2's Uint32 if Random is nil.
	Random func() uint32
}

Generator allows to generate fake words.

func (Generator) Word

func (g Generator) Word() string

Word generates a fake word with arbitrary length.

Example
package main

import (
	"fmt"

	"thde.io/fakeword"
)

func main() {
	words := []string{
		"Psychotomimetic",
		"Pulchritudinous",
		"Consanguineous",
		"Trichotillomania",
	}

	dict := fakeword.Dictionary{}
	dict.Add(words...)

	gen := dict.Generator()
	fmt.Println(gen.Word())
}
Output:

func (Generator) WordWithDistance

func (g Generator) WordWithDistance(min int, max int) string

WordWithDistance returns a fake word with variable length. Running this function can be quite costly, as it will just generate fake words until one with the correct length appears.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL