pub fn random(buf: &mut [u8]) {
        Self::CRNG.with(|crng| {
            // get crng instance
            let mut crng = crng.borrow_mut();
            buf.iter_mut().for_each(|x| *x = 0);

            // create nonce
            let mut nonce = [0; 12];
            nonce[4..].copy_from_slice(&crng.counter.to_be_bytes());
            crng.counter += 1;

            // generate random bytes.
            ChaCha20Ietf
                .encrypt(buf, buf.len(), &crng.key, &nonce)
                .expect(line_error!());
        });
    }
// fill buffer with random bytes.
fill buffer with random bytes.
fill buffer with random bytes .
pub fn random(buf: &mut [u8]) {
        Self::CRNG.with(|crng| {
            // get crng instance
            let mut crng = crng.borrow_mut();
            buf.iter_mut().for_each(|x| *x = 0);
            // create nonce
            let mut nonce = [0; 12];
            nonce[4..].copy_from_slice(&crng.counter.to_be_bytes());
            crng.counter += 1;
            // generate random bytes.
            ChaCha20Ietf
                .encrypt(buf, buf.len(), &crng.key, &nonce)
                .expect(line_error!());
        });
    }
pub fn random ( buf : & mut [ u8 ] ) { Self :: CRNG . with ( | crng | { // get crng instance let mut crng = crng . borrow_mut ( ) ; buf . iter_mut ( ) . for_each ( | x | * x = 0 ) ; // create nonce let mut nonce = [ 0 ; 12 ] ; nonce [ 4 .. ] . copy_from_slice ( & crng . counter . to_be_bytes ( ) ) ; crng . counter += 1 ; // generate random bytes. ChaCha20Ietf . encrypt ( buf , buf . len ( ) , & crng . key , & nonce ) . expect ( line_error ! ( ) ) ; } ) ; }
fill buffer with random bytes.
fill buffer with random bytes .
buf
&mut [u8]