random() won't stay within its boundaries

Hello, World!

Just a quick problem:
random(0,160) returns in my case a lot of random numbers greater than 159 (up to 999), but random (10,20), random (100, 160) and/or random(0,100) are working just fine (It's the same when using RandomSeed()).
I'm using the Ardu Mega2560 Rev.3 and I'd like to know if you can reproduce my problem and maybe tell me what sort of wizardry is going on here :.

Greets from Germany,
Sebastian

Post your sketch, and we can try it.

okay, it's nothing big, just the LCD example with random numbers:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
long randNumber;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {

  lcd.setCursor(0, 1);
  randNumber = random(0, 160);
  lcd.print(randNumber);
  delay(1000);
}

You don't seem to be clearing the display between printing numbers. Are you sure it's not just overwriting the first one or two digits and leaving the rest as they were.

For example printing 159 followed by printing 54 in the same place might leave 549 on the display.

As I said: Just a small problem :wink:

Yep, added a clear() and everything is fine..

Thanks for the quick help!