Replies: 4 comments 1 reply
-
Wow, good catch! |
Beta Was this translation helpful? Give feedback.
-
This should be an issue. Converting. |
Beta Was this translation helpful? Give feedback.
-
It is interesting to note here that it affects the distribution of spheres and their materials in the final scene of the first book and first scene of the second book. My renders always looked different compared to renders presented in the book, i.e. I always got lots of metal balls and they were always purple. This helped me a lot, thanks. |
Beta Was this translation helpful? Give feedback.
-
For anyone who comes across this issue, there is a subtle bug in @niccolot's implementation in the first post. If you combine both That's why in the book the two functions are separate. Technically, since inline auto random_double(double min = 0, double max = 1)
{
static std::mt19937 gen;
return std::uniform_real_distribution{min, max}(gen);
} However, there is still a semantic issue with this implementation. It allows one to call this function like so: auto x = random_double(10); But, what does this mean? People familiar with python (see FWIW, you could do something like this to emulate python/bash behavior: inline auto random_double(double min, double max)
{
static std::mt19937 gen;
return std::uniform_real_distribution{min, max}(gen);
}
inline auto random_double(double max = 1) { return random_double(0, max); } Or, if you want to emulate the book behavior, but let c++ do the interpolation: inline auto random_double(double min, double max)
{
static std::mt19937 gen;
return std::uniform_real_distribution{min, max}(gen);
}
inline auto random_double() { return random_double(0, 1); } In either case, you still end up with two functions though. |
Beta Was this translation helpful? Give feedback.
-
I' ve just realized that one of the suggested way to generate random numbers, namely
produces numbers only in the first (min,max) range it is instanciated with, e.g.
prints
I think is kind of a coincidence that everything works regardless, the random_double() is always used with (0,1), the only problem could arise in
but i think it would not produce any particularly visible artifact.
Beta Was this translation helpful? Give feedback.
All reactions