Reputation: 49
Im trying to create a procedure that colors every patch in the world 1 of 5 possible colors. with a 20 percent chance of each. im trying to create conditions for each color so
If a number is less then 2 make it green.
If a number is less then 4 and greater then 1 make it blue.
If a number is less then 6 and greater then 3 make it red.
If a number is less then 8 and greater then 5 make it yellow.
If a number is less then 10 and greater then 7 make it purple.
starting off, I wrote
to fiveColors
if random 10 < 2 [ set pcolor red ]
end
but if I do this for every condition, random will be a different number everytime. I need to do random once and then set it against each condition, which I'm not sure how to do.
Upvotes: 0
Views: 528
Reputation: 1894
one way to do it is the way you wanted to do it :
Let b random 10
If b < 2 [set pcolor green]
If b < 4 and b > 1 [set pcolor blue]
If b < 6 and b > 3 [set pcolor red]
If b < 8 and b > 5 [set pcolor yellow]
If b > 7 [set pcolor violet]
but the simpler way is :
set pcolor one-of [green blue red yellow violet]
Upvotes: 1