Crate weird_data

source ·
Expand description

Generate random data in such a way as to make rare edge-cases very likely.

Disclaimer: the random number generators used in this crate are NOT CRYPTOGRAPHICALLY SECURE. Only use these generators for generating testing inputs, do not rely on them for cryptographic purposes in production code! For instance, you may test a cryptographic tool with these generators, but you may not deploy code that relies on these generators for security in production.

For instance, if generating a random f32 by uniformly sampling 32 bits of data, certain values will rarely appear, such as NAN and INFINITY. When doing randomized testing, like fuzzing, it isn’t very useful to repeatedly generate well-behaved data. It is much more useful if we can artificially increase the likelihood of these special values, so that we test with them more often.

Additionally, some random number crates will never generate certain problematic bit-patterns, such as NAN.

This crate is based on the fastrand crate.

This crate can work with no_std, if you disable the std feature. You cannot use the global functions when in a no_std environment. In that case, you can explicitly instantiate Wdg and call the methods on it. They are equivalent.

If using std, it’s more ergonomic to use the global functions in the [global_functions] module.

Structs

  • A weird data generator

Functions

  • Generate a random f32, such that special or problematic values are much more common than normal.
  • Generate a random f64, such that special or problematic values are much more common than normal.
  • Gives back the current seed that is being held by the thread-local generator.
  • Generate a random i8 , such that special or problematic values are much more common than normal.
  • Generate a random i16 , such that special or problematic values are much more common than normal.
  • Generate a random i32 , such that special or problematic values are much more common than normal.
  • Generate a random i64 , such that special or problematic values are much more common than normal.
  • Generate a random i128 , such that special or problematic values are much more common than normal.
  • Generate a random isize , such that special or problematic values are much more common than normal.
  • There are multiple bit patterns that are equivalent to a NAN. This generator covers all possible NAN values as specified in IEEE-754, even ones that Rust would normally not generate.
  • Generates a random f64 NAN value.
  • Generate a random f32 normal value
  • Generate a random f64 normal value
  • Initialize the thread-local generator with the given seed.
  • Generate a random f32 “special” value
  • Generate a random f64 “special” value
  • Generate a random i8 “special” value
  • Generate a random i16 “special” value
  • Generate a random i32 “special” value
  • Generate a random i64 “special” value
  • Generate a random i128 “special” value
  • Generate a random isize “special” value
  • Generate a random u8 “special” value
  • Generate a random u16 “special” value
  • Generate a random u32 “special” value
  • Generate a random u64 “special” value
  • Generate a random u128 “special” value
  • Generate a random usize “special” value
  • Generates a random f32 denormal value.
  • Generates a random f64 denormal value.
  • Generate a random u8 , such that special or problematic values are much more common than normal.
  • Generate a random u16 , such that special or problematic values are much more common than normal.
  • Generate a random u32 , such that special or problematic values are much more common than normal.
  • Generate a random u64 , such that special or problematic values are much more common than normal.
  • Generate a random u128 , such that special or problematic values are much more common than normal.
  • Generate a random usize , such that special or problematic values are much more common than normal.