nature-of-code / The-Nature-of-Code-archive

The very first build system for The Nature of Code
http://natureofcode.com
913 stars 151 forks source link

Introduction: Incorrect uses of random(-1, 1) in Walker's step method #338

Closed kjkuan closed 10 years ago

kjkuan commented 10 years ago

In the Introduction page, I find that the use of random(-1, 1) doesn't work as expected without rounding. I think it should be used like this:

x += round(random(-1, 1));
y += round(random(-1, 1));

Note: I'm using Processing 2.0.2 on Mac OS X.

scotthmurray commented 10 years ago

What about the code isn't working as expected? What happens instead?

I'm guessing you're getting an error, because x and y start out as ints in this chapter. Yet random(-1, 1) returns a float, so make sure you've changed x and y to floats.

shiffman commented 10 years ago

I checked and the text explicitly mentioned the need for floating points so I think this issue can be closed.