Commit d3cd7bfe authored by Jan Möbius's avatar Jan Möbius
Browse files

Random number generator now works with size_t

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@869 fdac6126-5c0c-442c-9429-916003d36597
parent 420b5e59
......@@ -63,12 +63,12 @@ namespace OpenMesh {
//== IMPLEMENTATION ===========================================================
RandomNumberGenerator::RandomNumberGenerator(const double _resolution) :
RandomNumberGenerator::RandomNumberGenerator(const size_t _resolution) :
resolution_(_resolution),
iterations_(1),
maxNum_(RAND_MAX + 1.0)
{
double tmp = resolution_;
double tmp = double(resolution_);
while (tmp > (double(RAND_MAX) + 1.0) ) {
iterations_++;
tmp /= (double(RAND_MAX) + 1.0);
......@@ -91,7 +91,7 @@ double RandomNumberGenerator::getRand() const {
return randNum / maxNum_;
}
double RandomNumberGenerator::resolution() const {
size_t RandomNumberGenerator::resolution() const {
return maxNum_;
}
......
......@@ -56,6 +56,8 @@
#include <OpenMesh/Core/System/config.h>
#include <cstdlib>
//== NAMESPACES ===============================================================
......@@ -68,6 +70,7 @@ namespace OpenMesh {
/** Generate a random number between 0.0 and 1.0 with a guaranteed resolution
* ( Number of possible values )
*
* Especially useful on windows, as there MAX_RAND is often only 32k which is
* not enough resolution for a lot of applications
......@@ -80,20 +83,20 @@ public:
*
* @param _resolution specifies the desired resolution for the random number generated
*/
RandomNumberGenerator(const double _resolution);
RandomNumberGenerator(const size_t _resolution);
/// returns a random double between 0.0 and 1.0 with a guaranteed resolution
double getRand() const;
double resolution() const;
size_t resolution() const;
private:
/// desired resolution
const double resolution_;
const size_t resolution_;
/// number of "blocks" of RAND_MAX that make up the desired _resolution
unsigned int iterations_;
size_t iterations_;
/// maximum random number generated, which is used for normalization
double maxNum_;
......
......@@ -116,7 +116,7 @@ update_buffer(VHierarchyNodeHandle _node_handle)
if (buffer_[none_zero_pos] != 0) break;
}
window_max_ = buffer_min_ + none_zero_pos + 1;
for(none_zero_pos=0; none_zero_pos < buffer_size(); ++none_zero_pos)
for(none_zero_pos=0; none_zero_pos < int(buffer_size()); ++none_zero_pos)
{
if (buffer_[none_zero_pos] != 0) break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment