Question

How do I randomly select one of 3 procedures?

Please see below:

to move
   ifelse random-float 100 < 70 
   [move-forward]
   [move-left move-right move-back] ;; To randomly select one of these 3 procedures to execute.
end

Thank you. I am quite unfamiliar with the syntax.

Was it helpful?

Solution

run one-of (list task move-left
                 task move-right
                 task move-back)

OTHER TIPS

Maybe not too much elegant, but that may work:

to move
  ifelse random-float 100 < 70 
  [move-forward]
  [let n random 3
    ifelse n = 0
    [move-left]
    [ifelse n = 1
      [move-right]
      [move-back]]]
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top