How to hatch turtles with probability

拟墨画扇 提交于 2019-12-11 11:40:37

问题


I'm trying to find a procedure to hatch a turtle based on random probability:

  • 40% for A
  • 30% for B
  • 30% for C

How do you hatch a turtle depending on that probability? What procedure/s should I use?


回答1:


It looks like A, B, and C are breeds? Then

to weighted-hatch ;; turtle-proc
  let p random-float 100
  if (p >= 60) [hatch-As 1 [init-A]]
  if (if p >= 30 and p < 60) [hatch-Bs 1 [init-B]]
  if (p < 30) [hatch-Cs 1 [init-C]]
end
to init-A
  ;;put any desired initializations here
end

Etc.

You could alternatively use the rnd extension; see NetLogo, weighted random draw from a list: how to use rnd-extension?




回答2:


Throw a dice mate! : ) Generate a random number, since you have 3 probable options you can use something like random-float 1 this gives a number in [0,1).

Then, if 0>= number <=0.4 hatch A, else if 0.4< number <=0.7 hatch B and so on for C.

Happy coding!



来源:https://stackoverflow.com/questions/29156262/how-to-hatch-turtles-with-probability

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!