devela::_dep::stringzilla::sz

Function randomize

pub fn randomize<T, A>(text: &mut T, alphabet: &A)
where T: AsMut<[u8]> + ?Sized, A: AsRef<[u8]> + ?Sized,
Available on crate feature dep_stringzilla only.
Expand description

Randomizes the contents of a given byte slice text using characters from a specified alphabet. This function mutates text in place, replacing each byte with a random one from alphabet. It is designed for situations where you need to generate random strings or data sequences based on a specific set of characters, such as generating random DNA sequences or testing inputs.

§Type Parameters

  • T: The type of the text to be randomized. Must be mutable and convertible to a byte slice.
  • A: The type of the alphabet. Must be convertible to a byte slice.

§Arguments

  • text: A mutable reference to the data to randomize. This data will be mutated in place.
  • alphabet: A reference to the byte slice representing the alphabet to use for randomization.

§Examples

use stringzilla::sz;
let mut my_text = vec![0; 10]; // A buffer to randomize
let alphabet = b"ACTG"; // Using a DNA alphabet
sz::randomize(&mut my_text, &alphabet);

After than, my_text is filled with random ‘A’, ‘C’, ‘T’, or ‘G’ values.