import random


def _gsa_update_velocity(velocity, acceleration):
    """Stochastically update velocity given acceleration.

    In GSA paper, velocity is v_i, acceleration is a_i
    """

    # The GSA algorithm specifies that the new velocity for each dimension
    # is a sum of a random fraction of its current velocity in that dimension,
    # and its acceleration in that dimension
    # For this reason we sum the dimensions individually instead of simply
    # using vec_a+vec_b
    new_velocity = []
    for vel, acc in zip(velocity, acceleration):
        new_velocity.append(random.uniform(0.0, 1.0) * vel + acc)
    return new_velocity