Skip to content

Commit

Permalink
Support user-defined random number generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Aug 13, 2018
1 parent 158ad52 commit 508246b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion PerlinNoise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// siv::PerlinNoise
// Perlin noise library for modern C++
//
// Copyright (C) 2013-2016 Ryo Suzuki <[email protected]>
// Copyright (C) 2013-2018 Ryo Suzuki <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files(the "Software"), to deal
Expand Down Expand Up @@ -64,6 +64,12 @@ namespace siv
reseed(seed);
}

template <class URNG>
explicit PerlinNoise(URNG& urng)
{
reseed(urng);
}

void reseed(std::uint32_t seed)
{
for (size_t i = 0; i < 256; ++i)
Expand All @@ -79,6 +85,22 @@ namespace siv
}
}

template <class URNG>
void reseed(URNG& urng)
{
for (size_t i = 0; i < 256; ++i)
{
p[i] = i;
}

std::shuffle(std::begin(p), std::begin(p) + 256, urng);

for (size_t i = 0; i < 256; ++i)
{
p[256 + i] = p[i];
}
}

double noise(double x) const
{
return noise(x, 0.0, 0.0);
Expand Down

0 comments on commit 508246b

Please sign in to comment.