Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
Assignees
@AkramIzz

Description

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

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /