Listing 2: class RandomHeight implementation

#include <stdlib.h>
#include "RandomHeight.h"

RandomHeight::RandomHeight
    (int maxLvl, float prob)
{
  randomize();
  maxLevel = maxLvl;
  probability = prob;
}

int RandomHeight::newLevel(void)
{
int tmpLvl = 1;
  // Develop a random number between 1 and
  // maxLvl (node height).
  while ((random(2) < probability) &&
         (tmpLvl < maxLevel))
    tmpLvl++;

  return tmpLvl;
}

//End of File