GitXplorerGitXplorer
a

randline

public
0 stars
0 forks
0 issues

Commits

List of commits on branch main.
Unverified
d5931463e1832548d7e509f3cf525b5d166850ce

Pick a better name for this

aalexwlchan committed 4 days ago
Unverified
a5485a5c747b332bd5f653ce91a524f33fe83210

Pick weights from the range U[0,1]

aalexwlchan committed 4 days ago
Verified
66df6d72aafeacfb637ffdc1da3980271fc2b28b

Merge pull request #4 from alexwlchan/f32-weights

aalexwlchan committed 6 days ago
Unverified
1bb15ba73016c4a93d0adbb52fb9e6467ce79369

Use f64 for weight, not i32

aalexwlchan committed 6 days ago
Unverified
631b2995829e01ccd2d633861b130792bfcbbad4

Bump to 1.0.0

aalexwlchan committed 8 days ago
Verified
2ac26395cf8bf63fb1cf931f8ac711cfcd494836

Merge pull request #2 from alexwlchan/add-cli-tests

aalexwlchan committed 8 days ago

README

The README file for this repository.

randline

This tool picks one or more random lines from a file (or anything else you pass to it).

$ randline < /usr/share/dict/words
Urania

$ randline 3 < /usr/share/dict/words
foolhardiness
rhinoscopic
wormhood

How it works

This tool uses reservoir sampling to select the random lines; in particular Algorithm L.

I wrote it as a way to understand how reservoir sampling works, and to try using Rust generics. Although the final tool only deals with strings, the underlying reservoir_sample can sample iterators of any type.

Installation

You can download compiled binaries from the GitHub releases.

Alternatively, you can install from source. You need Rust installed; I recommend using Rustup. Then clone this repository and compile the code:

$ git clone "https://github.com/alexwlchan/emptydir.git"
$ cd emptydir
$ cargo install --path .

Usage

You need to pipe input to randline. If you don't pass an argument, it will print a single random line.

$ randline < /usr/share/dict/words
blithen

You can choose the number of random lines to print by passing a single argument k:

$ randline 3 < /usr/share/dict/words
unprofessed
ragout
Tarpeia

You can also pipe the output of another command to it, for example if I wanted to find 5 random words starting with 'a':

$ grep '^a' /usr/share/dict/words | randline 5
approachabl
autecological
alogical
ambrain
anticonstitutionally

License

MIT.