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

The very first build system for The Nature of Code

Home Page:http://natureofcode.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

kjkuan opened this issue · comments

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.

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.

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