Help with random seed

187 views
Skip to first unread message

vidus...@gmail.com

unread,
Jun 16, 2021, 10:07:58 PM6/16/21
to netlogo-users
Hi All 

I am running a decision model for one year. The model has a chooser to select different resource availability: "current" or "future".  I am comparing current vs future distance-travelled for each agent. 
Since the agents are generated from randomle selected patches with [pcolor = black] , is there a way to code so that the agents can maintain their location when I run the model for both the scenario? 

I am not sure what does randome seed do but when I used random-seed  0 as the fiest line of my setup code,  it does the job but I am not sure what is actually happening here and I don't think I understand the description very well. 
I have some randomly assigned patch variables (e.g. richness ) too. If I used random-seed in the begining of setup like :

to setup 
ca
random-seed 0 
setup-patches
setup-turtles
reset-ticks
end 

Would this also affect patch variables (e.g. same value for richness for every run ) ? 

Can anyone help me with this question?

Kind Regards

Vidushi

jeremy...@northwestern.edu

unread,
Jun 17, 2021, 9:47:01 AM6/17/21
to netlogo-users
I think relevant section of the docs is here:  http://ccl.northwestern.edu/netlogo/docs/programming.html#random-numbers

And some quotes:

> Here’s how it works. NetLogo’s random number generator can be started with a certain seed value, which must be an integer in the range -2147483648 to 2147483647. Once the generator has been “seeded” with the random-seed command, it always generates the same sequence of random numbers from then on. For example, if you run these commands:

> random-seed 137 
> show random 100 
> show random 100 
> show random 100

> You will always get the numbers 79, 89, and 61 in that order.

And in testing in NetLogo 6.2.0, I see the same numbers output in that order when I run those commands.  So if you are setting the `random-seed` and then randomly generating a value for your `richness` variable, it should get the same value every time.

Also of note from the docs is this:

> The NetLogo primitives with “random” in their names (random, random-float, and so on) aren’t the only ones that use pseudo-random numbers. Many other operations also make random choices. For example, agentsets are always in random order, one-of and n-of choose agents randomly, the sprout command creates turtles with random colors and headings, and the downhill reporter chooses a random patch when there’s a tie. All of these random choices are governed by the random seed as well, so model runs can be reproducible.

So using the same random seed means your model will always have the same behavior on each run, for the same starting settings (widget values).  

If you want your setup to be the same every time but the actual "run" of your model to vary with different random seeds, you could try using the `new-seed` primitive like this:

```
to setup 
ca
  random-seed 0 ; set an unchanging random seed for setup, so all runs will start from the same place (at least, the same for any widget values used in setup)
  setup-patches
  setup-turtles
  reset-ticks
  random-seed new-seed ; set a new random seed for this "run" - so each run is different from this point on.
end 
```

I hope that helps!

-Jeremy
Reply all
Reply to author
Forward
0 new messages