import random


def normalRandomInt(max_val, spread, skew=0):
  """Returns a random integer from a normal distribution whose parameters may be
  tweaked by setting max_val, spread and skew. The value is clipped to
  the range [0, max_val].

  Args:
    max_val {number} A positive number. All returned values will be less than
      this.
    spread {float} Should be a value between 0 and 1. The standard deviation of
      the normal distribution will be set to this value times max_val.
    skew {float} Should be value between -1 and 1. The mean of the normal
      distribution will be set to max_val * 0.5 * (1 + skew).

  Returns:
    {int} A random integer in the range [0, max_val].
  """
  mu = max_val * 0.5 * (1.0 + skew)
  sigma = max_val*spread
  x  = int(random.normalvariate(mu, sigma))
  # Ensure the value is in the range [0, max_val]
  return max(0, min(x, max_val))