How to use omni.replicator.core.modify.register API?

As title,
I want to keep regenerating the number and position of cube groups in each trigger, I think the omni.replicator.core.modify.register API can solve my problem, but I’m not sure how to use it, I used it in that way, but I got an error.
Or if there have any others API is more suitable for me, feel free to tell me!

Thanks!

    with rep.trigger.on_frame(num_frames=3, interval=200):
        group = create_cube_group(random.randint(10,19), random.randint(1,3))
        with group:
             **rep.modify.register**(
                 create_cube_group(random.randint(10,19), random.randint(1,3)), override=True
            )

Error: AttributeError: __ enter __
image