
Laurent_R
Enthusiast
Sep 16, 2012, 1:12 AM
Post #2 of 2
(834 views)
|
|
Re: [Lynn] Infectious Random Walk
[In reply to]
|
Can't Post
|
|
In the second inner loop, you are comparing $random_num with $n. But $n isn't defined anywhere in the code you posted. Even if it was defined, I can't see how this comparison would yield you the desired result. You are just comparing a random number with $n, even assuming $n is defined somewhere else, the probability of an exact match is very very low, close to 0 (on my system, rand returns a number with 16 decimal digits, the probability of an exact match is of the order of 1/1,000,000,000,000,000,; if you run this program 100 times second, the chances are that you will most probably not get a hit in 100,000 years). Actually, I don't even understand what you are trying to do with this second inner loop. The first inner loop also has flaws: you are not checking that your moves don't get you out of the grid. You should have minimal and maximal values for $xpos and $ypos and decide what to do when using the random number would lead you to walk outside of the grid. Final point: you should "use strict;" and "use warnings". This would give you a number of diagnostics on your code and declare most on your variables in limited lexical scope (with my).
|