Closed arthurhjorth closed 8 years ago
Actually, thinking more about it, this might be the right analogy:
let atask task [ask turtles [show ?]] (run atask random 10)
and for this, they do all get the same random. So maybe that's just how it works.
But then - what would be the best way to inject a new random number into each model? Would we have to do a foreach ls:models
thing? (Disregarding potential problems with implementation,) shouldn't we be able to use ls:ask
+ argument for this?
So it works that way just because that's how arguments work in general. ls:ask
isn't special; the arguments are evaluated before the function is evaluated. Anyway, I think you figured that out.
Why are these models starting with the same seed? Are you intentionally doing that?
The way around it would be something like:
foreach ls:models [
ls:let num random 10
ls:ask ? [ ask patches [ set plabel num ] ]
]
Note that there's no difference between ls:let
and an argument here. I could've used an argument, I just think this reads better.
So yeah, not a bug. That's just how NetLogo works. We could think about passing tasks in to child models or something, but that would hard and weird and only marginally useful as far as I can tell. The case where all children use the same seed, but you want to give them a different random number seems pretty niche to me, and the foreach solution is pretty easy.
Another possibility would be something like ls:let
that exposes parent procedures to children, but again, hard and weird enough that we should think very carefully before doing that.
BTW you should jump on chat sometime. Hope you're having a good time at the conference!
I have a bunch of open models with the same random seed. Let's say that I want to ask all of these models to set all of their patches' plabel to a number between 0 and 9. Because they have the same random seed, I need to inject a random from the parent model. I think I would expect that this would give a new number for each of my models using this:
(ls:ask ls:models [ask patches [set plabel ?]] random 10)
However, the random 100 is only run once, resulting in models all receiving the same number. Is this working as intended? I think the best analogy I can come up with for turtles would be:
let atask task [show ?] ask turtles [(run atask random 10)]
In this, all turtles run the task + random. I know that this goes inside the command task so maybe it's just not the right analogy. Maybe there isn't one, or maybe there is one but I can't think of it?
What do you think?