mod

 

mod is a mathematics primitive that completes the modulo operation, which takes two numbers, divides them, and returns the remainder. For example, 17 mod 7 would report 3 because $17 = 2 * 7 + 3$.

mod is very useful in some interesting NetLogo modeling applications such as creating grids. For example, the following code would create a checkerboard pattern like a chess board:

ask patches [
  if (pxcor + pycor) mod 2 = 1 [
    set pcolor white
  ]
]

Things to keep in mind when using mod:

In the model example below, we use mod to create a maze in which 3 mice compete for the pieces of food scattered around randomly. Without mod, creating this maze would be extremely tedious.

 

Try it Yourself