Skip to content

robby031/ax-rnd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ax-rnd

Fast and lightweight random number generator library and CLI tool for Rust.

  • Small single-state RNG
  • Fast bulk operations
  • Pure Rust implementation
  • no_std support
  • Installable CLI tool

ax-rnd docs-ax-rnd no_std rust license


Installation

Library

[dependencies]
ax-rnd = "0.1"

CLI

cargo install ax-rnd

Quick Start

Convenience API

use ax_rnd::{
    u32,
    u64,
    bool,
    f64,
    alphanumeric,
    base64url,
    fill,
};

let n = u64();
let ok = bool();

let token = alphanumeric(32);
let url = base64url(32);

let mut buf = [0u8; 1024];
fill(&mut buf);

Seeded RNG

use ax_rnd::rng;

let mut rng = rng(12345);

let x = rng.next_u64();
let y = rng.next_u32();
let f = rng.next_f64();

Bounded Numbers

use ax_rnd::rng;

let mut rng = rng(42);

let x = rng.bounded_u64(100);
let y = rng.bounded_u32(50);

Random Strings

use ax_rnd::rng;

let mut rng = rng(42);

let alpha = rng.alpha(32);
let token = rng.token(32);

Bulk Operations

use ax_rnd::rng;

let mut rng = rng(42);

let mut bytes = [0u8; 1024];
rng.fill_bytes(&mut bytes);

let mut u64s = [0u64; 16];
rng.fill_u64(&mut u64s);

State Management

use ax_rnd::AxRng;

let mut rng = AxRng::new(12345);

let state = rng.state();

let restored = AxRng::from_raw(state[0]);

let other = rng.split();

rng.reseed(999);

Top-level Helpers

use ax_rnd;

let x = ax_rnd::random_u64(42);

let token = ax_rnd::token(42, 32);

let bounded = ax_rnd::bounded_u64(42, 100);

CLI Usage

ax_rnd <command> [args]
Command Description
bytes Generate random bytes
alpha Generate alphanumeric string
token Generate URL-safe token
shuffle Shuffle input lines
u64 Generate random numbers
uuid Generate UUID v4

CLI Examples

ax_rnd bytes 32 --hex

ax_rnd alpha 16

ax_rnd token 32

ax_rnd u64 5

ax_rnd uuid 3

Notes

  • Deterministic when using fixed seeds
  • Portable pure Rust implementation
  • Suitable for fast non-cryptographic randomness
  • Supports no_std

Links


License

MIT

About

Axrnd is a fast, small random number generator (rnd) library and CLI tool written in Rust.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors

Languages