Skip to content

[Book1] Ch9 Rendering color wrong #1282

@Penguin-SAMA

Description

@Penguin-SAMA

I have encountered a strange issue.
When I use the following piece of code:

inline double random_double() {
    static std::uniform_real_distribution<double> distribution(0.0, 1.0);
    static std::mt19937 generator;
    return distribution(generator);
}

inline double random_double(double min, double max) {
    return min + (max - min) * random_double();
}

The output in image.ppm is like this:
image

However, if I modify the code to this:

inline double random_double() { return rand() / (RAND_MAX + 1.0); }

image.ppm changes to this:
image

I am not sure what is going wrong, and after a detailed review of the code, I couldn't find any issues.
How should I modify the program to address this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions