Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ZipFile committed Aug 17, 2024
1 parent 7bf1fec commit 66cbfc5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ custom `machine_id`, `start_time` etc.
- `machine_id` should be an integer value upto 16-bits, callable or
`None` (will be used random machine id).

If you need to generate ids at rate more than 256ids/10msec, you can use the `RoundRobin` wrapper over multiple `SonyFlake` instances:

``` python
from timeit import timeit
from sonyflake import RoundRobin, SonyFlake, random_machine_ids
sf = RoundRobin([SonyFlake(machine_id=_id) for _id in random_machine_ids(10)])
t = timeit(sf.next_id, number=100000)
print(f"generated 100000 ids in {t:.2f} seconds")
```

> :warning: This increases the chance of collisions, so be careful when using random machine IDs.
For convenience, both `SonyFlake` and `RoundRobin` implement iterator protocol (`next(sf)`).

## License

The MIT License (MIT).
Expand Down

0 comments on commit 66cbfc5

Please sign in to comment.