Expand description
Random utf8 utility. This crate is #![no_std]
but requires alloc
.
Example
let mut rng = rand::rngs::SmallRng::seed_from_u64(0);
let my_str = rand_utf8::rand_utf8(&mut rng, 32);
assert_eq!(32, my_str.as_bytes().len());
Functions
Generate a valid random unicode string, targeting well distributed utf8 bytes. rand::distributions::DistString produces random u32 code points, but the majority of these code points produce 4 utf8 bytes each of which are > 128, resulting in poor distribution. This function mixes in random valid utf8 bytes < 128 to fix this issue. Bytes may not be very well distributed if len < 8.