# DistString in rand::distributions - Rust
`String` sampler
Keywords: rust, rustlang, rust-lang, DistString

# Trait rand::distributions::DistString

source · [−]

    pub trait DistString {
        fn append_string<R: Rng + ?Sized>(
            &self,
            rng: &mut R,
            string: &mut String,
            len: usize
        );

        fn sample_string<R: Rng + ?Sized>(&self, rng: &mut R, len: usize) -> String { ... }
    }

Expand description

`String` sampler

Sampling a `String` of random characters is not quite the same as collecting a sequence of chars. This trait contains some helpers.

## Required Methods

source

#### fn append_string<R: Rng + ?Sized>(
&self,
rng: &mut R,
string: &mut String,
len: usize
)

Append `len` random chars to `string`

## Provided Methods

source

#### fn sample_string<R: Rng + ?Sized>(&self, rng: &mut R, len: usize) -> String

Generate a `String` of `len` random chars

## Implementors

source

### impl DistString for Alphanumeric

source

### impl DistString for Standard

Note: the `String` is potentially left with excess capacity; optionally the user may call `string.shrink_to_fit()` afterwards.