Skip to content

Fixing draw_alpha

In the ReseedableRng trait, the method draw_alpha can fail if the random bytes cannot be deserialized into an element F.

I can be fixed by just looping until next_bytes returns something valid as it is shown in ffd45df6

    fn draw_alpha<F: Field>(&mut self) -> F {
        loop {
            if let Some(alpha) = self.next_bytes(|bytes| F::from_random_bytes(bytes)) {
                return alpha;
            }
        }
    }