Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
PseudoRandom: Expose constant PSEUDORANDOM_MAX
  • Loading branch information
kwolekr committed Dec 28, 2014
1 parent 8334100 commit 8c98f49
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/noise.h
Expand Up @@ -30,6 +30,8 @@
#include "irr_v3d.h"
#include "util/string.h"

#define PSEUDORANDOM_MAX 32767

This comment has been minimized.

Copy link
@HybridDog

HybridDog Dec 29, 2014

Contributor

I think you could set PSEUDORANDOM_MAX to 32768 and remove the +1


extern FlagDesc flagdesc_noiseparams[];

class PseudoRandom
Expand All @@ -45,15 +47,15 @@ class PseudoRandom
{
m_next = seed;
}
// Returns 0...32767
// Returns 0...PSEUDORANDOM_MAX
int next()
{
m_next = m_next * 1103515245 + 12345;
return((unsigned)(m_next/65536) % 32768);
return((unsigned)(m_next/65536) % (PSEUDORANDOM_MAX + 1));
}
int range(int min, int max)
{
if(max-min > 32768/10)
if (max-min > (PSEUDORANDOM_MAX + 1) / 10)
{
//dstream<<"WARNING: PseudoRandom::range: max > 32767"<<std::endl;
assert(0);
Expand Down

0 comments on commit 8c98f49

Please sign in to comment.