raytracing.github.io
raytracing.github.io copied to clipboard
In One Weekend: Improvement - PPM's potential not present and random device as seed
Hi, recently I relearn the book 1 and find some potential improvements:
- PPM format encoding: On Windows 11 or 10, default encoding of terminal is utf-16le while on Linux is utf-8, which might makes image viewer failed to show ppm image on Windows. Reencoding the ppm file with utf-8 will fix that. I think better mention it in the book for beginners' convenience.
- In rtweekend.h, in random_double() function, use
std::random_device
as the seed for mt19937 generator, which gives better randomization.
inline double random_double()
{
// Returns a random real in [0,1)
static std::random_device rd;
static std::uniform_real_distribution<double> distribution(0.0, 1.0);
static std::mt19937 generator(rd());
return distribution(generator);
}