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

 
 
 
 
 
 
 

What's next?

Once you mastered the mod primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the mod primitive:
 
 
Similar primitives:
mean

Reports the average of a provided list of numerical values.

Read more
count

Counts the number of agents in an agentset.

Read more
if

Carries out a provided set of rules (code) if a given condition is true. Does nothing if a given condition is false.

Read more
any?

Checks if there is at least one agent in an agentset.

Read more
 
Learn another primitive: