random-float

 

random-float is a mathematics primitive that reports a random floating point number anywhere between 0 and the given number. For instance, random-float 10 could report 6.9105, 7, 4.2, 0.451, 0.0000001, 9.99999, etc. random-float is very useful in modeling phenomena that require continuous numbers. For example, if we wanted to create a model where we wanted to have people with various heights, we could write the following code, which would make each person have a random height between 5 feet to 7 feet:

create-people 100 [
    set size 5 + random-float 2
]

Things to keep in mind when using random-float:

In the model example below, we use random-float to randomly place a dart somewhere on (or off of) a dartboard. By using random-float, we are ensuring that the dart could land at every possible point on the dartboard, not just integer points.

 

Try it Yourself

 
 
 
 
 
 
 

What's next?

Once you mastered the random-float primitive, don't stop there. Check out the resources below to improve your NetLogo skills.

 
Published NetLogo models that use the random-float primitive:
 
 
Similar primitives:
random

Reports a random whole number between 0 and a specified number.

Read more
random-normal

Reports a random number with decimal points that is picked from over a normal distribution with a specified mean and standard deviation.

Read more
globals

Defines variables that can be accessed throughout the whole model and has the same value for all the agents.

Read more
turtles-own

Declare a variable that belongs to turtles.

Read more
 
Learn another primitive: