Loading ...
Sorry, an error occurred while loading the content.

store a randomly produced grid

Expand Messages
  • orth_axel
    store a randomly produced grid hi, to produce a random grid of plants (green) i use a slider for density and the procedure ask patches[ if (random 100)
    Message 1 of 2 , Dec 31, 2003
    • 0 Attachment
      store a randomly produced grid

      hi,
      to produce a random grid of plants (green) i use a slider for density
      and the procedure

      ask patches[
      if (random 100) < density
      [ set pcolor green]]

      in order to present different outcomes of my model for different
      inputs i also would like to have one fixed environment for certain
      densities

      therefor my question is:
      is it somehow possible to store a randomly created environment?
      if yes -> what must i do?

      thanks in advance
    • Steiner, James
      ... Yes. I can think of three options right off: First: stored random seed If you seed the random number generator with the same number, you get the same
      Message 2 of 2 , Jan 5, 2004
      • 0 Attachment
        > therefor my question is:
        > is it somehow possible to store a randomly created environment?
        > if yes -> what must i do?

        Yes.

        I can think of three options right off:

        First: stored random seed

        If you seed the random number generator with the same number, you get the
        same result.

        So, you can generate a particular, same-every-time setup by using that
        particular seed.

        E.g.:

        ;; assume slider called density, varying from 0 to 100
        ;; assume switch called use-preset?
        To generate-environment
        If use-preset?
        [ ; for no reason, using the density to seed the RNG.
        ; could use any single number or range of numbers
        ; doesn't really matter
        random-seed density
        ]

        Ask patches
        [
        ifelse [ random 100 < density ]
        [ set pcolor green ]
        [ set pcolor black ]
        ]
        End

        ~~~~~~~~

        Second: stored values in list, saved to csv (or otherwise)

        A second method would involve generating a random environment with a
        particular density, storing the results in a patch-owned list variable, then
        saving the list (via export-world, for example).

        To generate-enviro-list
        ;; assume patches-own e-list
        Locals [ index ]

        Ask patches
        [ ;; blank list
        set e-list []
        ]
        ; initial index
        Set index 0
        ; generate list
        Repeat 101
        [ ; set the density slider
        set density index
        ; set the patch colors
        generate-environment
        ; store the current patch color in the list
        ask patches
        [ set e-list lput pcolor e-list ]
        ; increment the index
        set index index + 1
        ]
        ;; put distinctive colors in patches to make it clear that
        ;; this is not a valid initial invironment
        Ask patches [ set pcolor blue - 3 + random 7 ]

        Export-world "e-list"
        End

        ~~~~

        To retrieve the preset, first import-world the list, then, as needed:

        ;; assume a button called "fetch preset" that runs this code
        ;; using the density slider to select the preset value

        To fetch-preset
        ask patches
        [ set pcolor item density e-list ]
        End

        ~~~~~

        The third way would be to use an algorithm to generate the preset.
        I don't know the math involved, but I'm thinking of the sort of
        integer-based non-random dithering algorithm that is/was used on 16-color
        and 256-color displays to simulate higher color depths. Or a half-toning
        algorithm. Like that.

        ~~~~~

        Hope this helps!

        ~~James










        ________________________________________________________________________
        This email has been scanned for all viruses by the MessageLabs Email
        Security System.
      Your message has been successfully submitted and would be delivered to recipients shortly.