Random Number GenerationΒΆ

Agent variables can be initialised with randomly generated data:

# Set the min and max initial positions
min_pos = -2.0f
max_pos = 2.0f

# For each agent
for i in range(populationSize):
    instance = population[i]

    # Randomly initialise the x, y and z variables with values between min_pos and max_pos
    instance.setVariableFloat("x", random.uniform(min_pos, max_pos))
    instance.setVariableFloat("y", random.uniform(min_pos, max_pos))
    instance.setVariableFloat("z", random.uniform(min_pos, max_pos))