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