smol-rs / fastrand

A simple and fast random number generator
Apache License 2.0
409 stars 35 forks source link

feat: Add an iterator selection function #51

Closed notgull closed 1 year ago

notgull commented 1 year ago

This PR adds an iterator selection function, choice(), that takes an ExactSizeIterator and chooses a random value from it. In addition, I reimplement functions like alphanumeric() using choice().

Right now, the API returns Option<I::Item>, since an iterator could be empty. However, it may be slightly more idiomatic to have it return I::Item and panic if given an empty/buggy iterator.