samedi 26 mai 2018

NetLogo: Assign Turtles Randomly but Equally to Different Groups

I used the code below to create 50 turtles and randomly assign them to one of four different strategies (i.e. a, b, c and d):

The problem is that when I decrease the number of created turtles or when I increase the number of strategies, I face a situation where at least one of the strategies is not taken by any turtle.

turtles-own [ my_strategy ]

to setup
  ;; create 50 turtles and assign them randomly
  ;; to one of four different strategies
  create-turtles 50 [
    set my_strategy one-of [ "a" "b" "c" "d" ]
  ]
end

I need your help here to: 1. Make sure that I do not face a situation where one or more strategies are not taken by any turtle. 2. Make sure that the number of turtles assigned to each strategy is roughly equal.




Aucun commentaire:

Enregistrer un commentaire