def diffusion_model_box_cyclic(random_moves, box_shape):
    """Diffusion in a box. Particles leaving box enter on opposite side."""
    positions = random_moves.copy()
    number_particles, duration, dimensions = positions.shape
    lower = tuple(-s // 2 for s in box_shape)
    for time in range(1, duration):
        temp = positions[:, time]
        temp += positions[:, time - 1]  # cumsum axis=1
        temp -= lower
        temp %= box_shape
        temp += lower
    return positions