Skip to content

Instantly share code, notes, and snippets.

@miura
Created May 16, 2013 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miura/5592101 to your computer and use it in GitHub Desktop.
Save miura/5592101 to your computer and use it in GitHub Desktop.
//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;
}
@miura
Copy link
Author

miura commented May 16, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment