rust-random / book

The Rust Rand Book
Other
49 stars 19 forks source link

Guide page for generating seeded random floats #7

Closed Harnesser closed 4 years ago

Harnesser commented 5 years ago

Hi all,

I'd love to see recipe page on the best way to generate seeded random floats for procedural generation applications.

This request comes from a recent unsuccessful experience I had trying to upgrade from 0.3 to 0.6 of rand. My 0.3 code uses a {SeedableRng, from_seed(), next_f32()} recipe I found on the web somewhere that's not suitable for 0.6, plus a --seed command line option to set the seed.

Thanks!

dhardy commented 5 years ago

Is this what you want?

Sorry, I don't quite follow. If you know how to improve the documentation though, a contribution would be very welcome!

To answer your bullet points:

dhardy commented 5 years ago

It's also worth noting that using gen_range or the Uniform distribution may be a little faster and more accurate than using gen() and modifying/shifting the result. Here's an expanded example.

Harnesser commented 5 years ago

Thanks - the first example was especially useful!

I would have like to have found a "recipe" page in the docs with:

I'd like to have a go at creating such a page for documentation, as thanks for your help. I'm not sure if the page would be best in the rand book, or in the main Rust Cookbook. What do you think?

Thanks again!

dhardy commented 5 years ago

I'm not sure if the page would be best in the rand book, or in the main Rust Cookbook. What do you think?

Depends where people are more likely to look for such documentation?

The book as it stands was written fairly quickly to at least have some doc beyond the API. It could certainly be expanded significantly. I can't gauge what content all readers want and also don't currently want to contribute new content to the book myself, but if you would like to I would be happy to review.