typinghumanizer

package
v0.0.0-...-6026c52 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdjacentKey

func AdjacentKey(rng *rand.Rand, ch rune) rune

AdjacentKey returns a random QWERTY neighbor of the given character. If the character has no known neighbors (non-letter), it returns the character itself unchanged.

func IsSentenceEnd

func IsSentenceEnd(chunk string) bool

IsSentenceEnd returns true if the chunk ends with sentence-ending punctuation (before any trailing whitespace).

func SplitWordChunks

func SplitWordChunks(text string) []string

SplitWordChunks splits text into word-sized chunks, keeping trailing whitespace and punctuation attached to the preceding word. For example, "Hello world. How are you?" becomes:

["Hello ", "world. ", "How ", "are ", "you?"]

func UniformJitter

func UniformJitter(rng *rand.Rand, baseMs, jitterMs, minMs int) time.Duration

UniformJitter returns a random duration in [baseMs-jitterMs, baseMs+jitterMs], clamped to a minimum of minMs.

Types

type Typo

type Typo struct {
	Pos  int      // Character index in the rune slice
	Kind TypoKind // What kind of typo
}

Typo describes a single typo at a position in the text.

func GenerateTypoPositions

func GenerateTypoPositions(rng *rand.Rand, textLen int, typoRate float64) []Typo

GenerateTypoPositions computes typo positions using uniform gap sampling (each gap is uniform on [halfGap, halfGap+avgGap)). O(typos) random calls, not O(chars). Returns a sorted slice of Typo structs.

type TypoKind

type TypoKind int

TypoKind identifies the type of typo to inject.

const (
	TypoAdjacentKey TypoKind = iota // Hit a neighboring key
	TypoDoubling                    // Type the character twice
	TypoTranspose                   // Swap current and next character
	TypoExtraChar                   // Insert a random adjacent key before the correct one
)

Jump to

Keyboard shortcuts

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