Ouroboroski
Ouroboroski

Reputation: 171

Netlogo: How to generate a list of random floats within a given interval?

I am a beginner with Netlogo and I am trying to generate a list with 3 items in it. I want these items to be random floats between 0.95 and 1.05.

I have declared this list as a "turtles-own" variable and I have attempted the following in the setup procedure:

ask turtles [ set fraction-list [ (0.95 + random-float 0.10) (0.95 + random-float 0.10) (0.95 + random-float 0.10) ] ]

Netlogo brings up an error saying: "Expected closing parenthesis." where the first "+" sign in the list is.

I am guessing Netlogo does not let you declare these variable within the list? I also tried to declare three variables beforehand like:

ask turtles [
let x (0.95 + random-float 0.10)
let y (0.95 + random-float 0.10)
let z (0.95 + random-float 0.10)
set fraction-list [ x y z]
]

However another error pops-up. It says "Expected a literal value." where the x is in the list.

Any ideas on how I could generate a list of random-floats within a given interval?

Thanks beforehand,

Carlos

Upvotes: 1

Views: 1288

Answers (1)

Luke C
Luke C

Reputation: 10301

Check out the n-values dictionary entry for more details, but that is probably the primitive you want:

turtles-own [ fraction-list ]

to setup 
  ca
  crt 3
  ask turtles [
    set fraction-list n-values 3 [ 0.95 + random-float 0.1 ]
    show fraction-list
  ]
  reset-ticks
end

Upvotes: 1

Related Questions