Skip to content

std::rand should be cast to double before division #1698

Open
@AkramIzz

Description

@AkramIzz

std::rand returns an integer when divided by RAND_MAX, the result will always be 0.

In Ray Tracing In One Weekend

inline double random_double() {
    // Returns a random real in [0,1).
    return std::rand() / (RAND_MAX + 1.0);
}

Should be (following book style)

inline double random_double() {
    // Returns a random real in [0,1).
    return double(std::rand()) / (RAND_MAX + 1.0);
}

Happy to make the change myself, just following the contribution guide.

PS: Thank you for the great books and all the work you put into this!! Let me know if you have a donate button somewhere (I couldn't find any), would love to buy you a coffee :).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions