Fast and easy random number generation.

Related tags

Text processing alea
Overview

alea

Crates.io Documentation License

A zero-dependency crate for fast number generation, with a focus on ease of use (no more passing &mut rng everywhere!).

The implementation is based on wyrand, a high-quality and fast generator.

This crate is heavily inspired by fastrand.

Usage

Add the following to your Cargo.toml:

[dependencies]
alea = "0.2"

Examples

Flip a coin:

if alea::bool() {
  println!("heads");
} else {
  println!("tails");
}

Generate a u64:

let u = alea::u64();

Fill a vector with random integers in some range:

let n = 1_000_000;

let mut v = vec![0; n];
for i in 0..n {
  v[i] = alea::i32_in_range(-200, 150);
}

Seed the generator to get reproducible results:

alea::set_seed(10);

Benchmarks

Benchmarks are run with criterion.rs. The reported values are the means and standard deviations. To run the benchmarks yourself, clone the repository and run

cargo bench
alea fastrand rand rand_pcg
f64 2.0002 ns +/- 21.718 ps 3.6868 ns +/- 40.030 ps 4.7417 ns +/- 75.082 ps 1.4531 ns +/- 73.249 ps
f32 2.0911 ns +/- 87.985 ps 2.6735 ns +/- 35.334 ps 1.8259 ns +/- 34.666 ps 1.4482 ns +/- 29.133 ps
u64 2.0062 ns +/- 13.639 ps 5.1602 ns +/- 132.48 ps 4.6494 ns +/- 68.218 ps 1.3561 ns +/- 7.0908 ps
u32 1.9777 ns +/- 4.3646 ps 4.5852 ns +/- 120.84 ps 1.6488 ns +/- 55.921 ps 1.3668 ns +/- 10.669 ps
u64 in range 4.5298 ns +/- 99.716 ps 5.1845 ns +/- 240.30 ps 9.8593 ns +/- 41.581 ps 5.4817 ns +/- 21.622 ps
u32 in range 2.6764 ns +/- 32.698 ps 4.3292 ns +/- 20.041 ps 5.5542 ns +/- 45.249 ps 4.9378 ns +/- 96.550 ps
i64 2.0042 ns +/- 23.321 ps 3.7119 ns +/- 44.196 ps 4.6275 ns +/- 63.446 ps 1.3506 ns +/- 17.385 ps
i32 1.9826 ns +/- 10.443 ps 2.6396 ns +/- 7.6008 ps 1.6326 ns +/- 26.437 ps 1.3668 ns +/- 7.4342 ps
i64 in range 4.4474 ns +/- 96.470 ps 3.8003 ns +/- 16.704 ps 5.6069 ns +/- 54.102 ps 5.5278 ns +/- 84.057 ps
i32 in range 2.4168 ns +/- 19.926 ps 2.7006 ns +/- 6.5716 ps 2.8754 ns +/- 26.128 ps 4.9530 ns +/- 179.12 ps
You might also like...
🛥 Vaporetto is a fast and lightweight pointwise prediction based tokenizer. This is a Python wrapper for Vaporetto.

🐍 python-vaporetto 🛥 Vaporetto is a fast and lightweight pointwise prediction based tokenizer. This is a Python wrapper for Vaporetto. Installation

Find files (ff) by name, fast!
Find files (ff) by name, fast!

Find Files (ff) Find Files (ff) utility recursively searches the files whose names match the specified RegExp pattern in the provided directory (defau

Fast suffix arrays for Rust (with Unicode support).
Fast suffix arrays for Rust (with Unicode support).

suffix Fast linear time & space suffix arrays for Rust. Supports Unicode! Dual-licensed under MIT or the UNLICENSE. Documentation https://docs.rs/suff

A fast implementation of Aho-Corasick in Rust.

aho-corasick A library for finding occurrences of many patterns at once with SIMD acceleration in some cases. This library provides multiple pattern s

Blazingly fast framework for in-process microservices on top of Tower ecosystem
Blazingly fast framework for in-process microservices on top of Tower ecosystem

norpc = not remote procedure call Motivation Developing an async application is often a very difficult task but building an async application as a set

Ultra-fast, spookily accurate text summarizer that works on any language
Ultra-fast, spookily accurate text summarizer that works on any language

pithy 0.1.0 - an absurdly fast, strangely accurate, summariser Quick example: pithy -f your_file_here.txt --sentences 4 --help: Print this help messa

A lightning-fast Sanskrit toolkit. For Python bindings, see `vidyut-py`.

Vidyut मा भूदेवं क्षणमपि च ते विद्युता विप्रयोगः ॥ Vidyut is a lightning-fast toolkit for processing Sanskrit text. Vidyut aims to provide standard co

Checks all your documentation for spelling and grammar mistakes with hunspell and a nlprule based checker for grammar

cargo-spellcheck Check your spelling with hunspell and/or nlprule. Use Cases Run cargo spellcheck --fix or cargo spellcheck fix to fix all your docume

A Markdown to HTML compiler and Syntax Highlighter, built using Rust's pulldown-cmark and tree-sitter-highlight crates.

A blazingly fast( possibly the fastest) markdown to html parser and syntax highlighter built using Rust's pulldown-cmark and tree-sitter-highlight crate natively for Node's Foreign Function Interface.

Owner
Jeff Shen
:)
Jeff Shen
Text Expression Runner – Readable and easy to use text expressions

ter - Text Expression Runner ter is a cli to run text expressions and perform basic text operations such as filtering, ignoring and replacing on the c

Maximilian Schulke 72 Jul 31, 2022
Easy reading and writing of `serde` structs to/from Google Sheets

serde_sheets Read and write structs directly from google sheets using serde and csv Implement serde::Serialize to write and serde::Deserialize to read

null 5 Jul 20, 2022
Generate easy to remember sentences that acts as human readable UUIDs 🥳

uuid-readable-rs Easy to remember unique sentences acting as UUID Generate easy to remember sentences that acts as human readable UUIDs. Built on UUID

Martin André 48 Nov 8, 2022
A simple and fast linear algebra library for games and graphics

glam A simple and fast 3D math library for games and graphics. Development status glam is in beta stage. Base functionality has been implemented and t

Cameron Hart 953 Jan 3, 2023
Rust edit distance routines accelerated using SIMD. Supports fast Hamming, Levenshtein, restricted Damerau-Levenshtein, etc. distance calculations and string search.

triple_accel Rust edit distance routines accelerated using SIMD. Supports fast Hamming, Levenshtein, restricted Damerau-Levenshtein, etc. distance cal

Daniel Liu 75 Jan 8, 2023
💥 Fast State-of-the-Art Tokenizers optimized for Research and Production

Provides an implementation of today's most used tokenizers, with a focus on performance and versatility. Main features: Train new vocabularies and tok

Hugging Face 6.2k Jan 5, 2023
A fast, low-resource Natural Language Processing and Text Correction library written in Rust.

nlprule A fast, low-resource Natural Language Processing and Error Correction library written in Rust. nlprule implements a rule- and lookup-based app

Benjamin Minixhofer 496 Jan 8, 2023
Vaporetto: a fast and lightweight pointwise prediction based tokenizer

?? VAporetto: POintwise pREdicTion based TOkenizer Vaporetto is a fast and lightweight pointwise prediction based tokenizer. Overview This repository

null 184 Dec 22, 2022
Composable n-gram combinators that are ergonomic and bare-metal fast

CREATURE FEATUR(ization) A crate for polymorphic ML & NLP featurization that leverages zero-cost abstraction. It provides composable n-gram combinator

null 3 Aug 25, 2022
Fast PDF password cracking utility equipped with commonly encountered password format builders and dictionary attacks.

PDFRip Fast PDF password cracking utility equipped with commonly encountered password format builders and dictionary attacks. ?? Table of Contents Int

Mufeed VH 226 Jan 4, 2023