The token bucket algorithm allows bursts while enforcing an average rate.
Implement create_token_bucket(capacity, refill_per_ms):
capacity — maximum tokens the bucket can hold.refill_per_ms — tokens added per millisecond (can be fractional).consume(tokens, timestamp) — attempt to consume tokens at virtual time timestamp. Returns True if allowed (enough tokens), False otherwise.
The bucket starts full (capacity tokens). Tokens are added based on elapsed
time since the last call: min(capacity, current + elapsed * refill_per_ms).
Sample tests