I am using an API that returns me articles in my language in determined categories. This API limits me in 100 calls for each interval of 60 minutes.
I don't want to make 100 calls straight away and make my script wait until 60 minutes has passed.
I could then shoot an API call every 36 seconds, but I also don't want the API calls to be shot evenly.
What is a feasible way to make my script make 100 API calls at random intervals of time, as long as the 100 fits in 60 minutes?
I thought of making a function that would generate 100 timestamps in this 60 minutes interval, and then at the right time of each timestamp, it would shoot an API call, but I think that'd be overkill, and I'm not sure how I could do that either.
What you could do is choose a min/max interval of how long you want to wait. Keep a note of how many requests have been made in the last 60 minutes and if you're still below the quota, download a document and wait for rand(min, max). This is not very fancy and doesn't distribute the wait times across the whole 60 minutes interval, but it's easy to implement.
Another way would be to randomly choose 100 numbers between 0 and 60*60. These are the seconds on which you make requests. Sort them and as you progress through the array, each time you wait for next - current seconds. (or even use the scheduler module to simplify it a bit)
How can I distribute 100 API calls randomly in a 60 minutes time interval?