Simulate a token-bucket rate limiter. allowed_requests(timestamps, capacity, rate) gets request times in seconds (sorted ascending; several requests can share a time) and returns one boolean per request: allowed or not.
- •The bucket holds at most
capacity tokens and is full at the time of the first request. - •Tokens refill continuously at
rate tokens per second of elapsed time, never beyond capacity. - •A request is allowed when the bucket holds at least one token; it then removes one. A rejected request removes nothing.
- •Treat a balance within
1e-9 of a whole token as a whole token, so floating-point rounding can't reject a request that earned its token.
An empty list returns [].
Python 3.13 in your browser — the standard library plus pandas and numpy; no pip installs.