Created
May 16, 2013 14:26
-
-
Save miura/5592101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//generating random steps | |
for(i =0; i<10; i++){ | |
print(randsteps()); | |
} | |
function randsteps(){ | |
direction = ""; | |
r = random(); | |
if (r < 0.25) | |
direction = "right"; | |
else if (r < 0.5) | |
direction = "up"; | |
else if (r < 0.75) | |
direction = "left"; | |
else | |
direction= "down"; | |
return direction; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This macro demonstrates how to choose four directions randomly.
The function "randomsteps()" is the key user-defined function. Line 8 generates a randome number between 0 and 1, and depending on its value, one of four directions is returned from the funciton.