raytracing.github.io icon indicating copy to clipboard operation
raytracing.github.io copied to clipboard

In One Weekend: Improvement - PPM's potential not present and random device as seed

Open Kethers opened this issue 1 year ago • 0 comments

Hi, recently I relearn the book 1 and find some potential improvements:

  1. 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.
  2. 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);
}

Kethers avatar Nov 05 '23 19:11 Kethers