Hopefully I understand your question :)
What about this:
Change the step: "When I set the speed to speed" to
When I set the speed to {speed} so that it takes an argument.
In your feature: When I test the speed 500 times
And in that step: When I test the speed 500 times you:
==>create a for loop 500 times:
=====>choose a random speed
=====>execute the other steps with context.execute_steps and format(speed)
You'll have to work around this a bit because it takes unicodes, not integers.
==> However, one might agree with Szabo Peter that it is a little awkward to use gherkin/python-behave for this :). It kind of messes up the purpose. Also, even in line of my thinking here, it might be done more elegantly.
You can find some nice stuff here: https://jenisys.github.io/behave.example/tutorials/tutorial08.html
Cheerz
So edit after comment: (after editing and writing this example it looks even more silly then I thought it would, so yeah: don't use behave for this.
Example:
Feature: test feature
Scenario: test scenario
given I open the app
when I test the app 500 times at random speed
then the console says it is done
steps:
@given(u'I open the app')
=>def I_open_the_app(context):
==>#code to open the app
@when(u'I test the app 500 times at random speed')
=>def I_test_the_app_500_times_at_random_speed(context):
==>for times in range(1,500):
===>random_speed = random.randint(min_speed,max_speed)
===>context.execute_steps(u'''when I play at {speed}'''.format(speed=str(random_speed))
@when(u'I play at {speed}')
=>def I_play_at(context,speed)
==>play_at_speed(int(speed))
@then(u'the console says it is done')
=>def the_console_says_it_is_done
==>print('it is done')