Can random(5) output the number 5?

So, given the code from here, these two lines would be equivalent:

  • println(rand.nextInt(6));
  • println(floor(random(6));

On another note concerning the use of random numbers, something many of us may have often noticed are statements such as this:

int r = random(255);
int r = random(255);
int r = random(255);
fill(r, g, b);

That is unfortunate, since it misses the opportunity to achieve a full range of colors, leaving out 255 as a possible resulting intensity value. This would be better:

int r = random(256);
int r = random(256);
int r = random(256);
fill(r, g, b);

Alternatively, we could do something like this:

int r = rand.nextInt(256);
int r = rand.nextInt(256);
int r = rand.nextInt(256);
fill(r, g, b);

See the discussion A newbie needs help.