hello77
hello77

Reputation: 51

How to hatch turtles with probability

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

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

Upvotes: 1

Views: 501

Answers (2)

Alan
Alan

Reputation: 9620

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?

Upvotes: 3

David Merinos
David Merinos

Reputation: 1295

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!

Upvotes: 1

Related Questions