Skip to content

Commit

Permalink
these random_double()'s are not so random...
Browse files Browse the repository at this point in the history
  • Loading branch information
alysssssa committed May 1, 2023
1 parent 0aae8b3 commit 023bc64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion raytracer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ hittable_list random_scene() {
auto material3 = make_shared<metal>(colour(0.7, 0.6, 0.5), 0.0);
world.add(make_shared<sphere>(point3(4,1,0), 1.0, material3));

return hittable_list(make_shared<bvh_node>(world, 0.0, 1.0));
return {make_shared<bvh_node>(world, 0.0, 1.0)};
}

int main() {
Expand Down
20 changes: 10 additions & 10 deletions raytracer/raytracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <limits>
#include <memory>
#include <cstdlib>
//#include <random>
#include <random>

using std::shared_ptr;
using std::make_shared;
Expand All @@ -21,24 +21,24 @@ inline double degrees_to_radians(double degrees) {
return degrees * pi / 180.0;
}

// alternative random number generator
//inline double random_double() {
// // random number in [0,1)
// return rand() / (RAND_MAX + 1.0);
//}

inline double random_double() {
// random number in [0,1)
return rand() / (RAND_MAX + 1.0);
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) {
// random number in [min,max)
return min + (max-min)*random_double();
}

// alternative random number generator
//inline double random_double2() {
// // random number in [0,1)
// static std::uniform_real_distribution<double> distribution(0.0,1.0);
// static std::mt19937 generator;
// return distribution(generator);
//}

inline int random_int(int min, int max) {
// random integer in [min,max]
return static_cast<int>(random_double(min, max+1));
Expand Down

0 comments on commit 023bc64

Please sign in to comment.