Skip to content

Commit c64ff0d

Browse files
committed
Make MachineIDLCG callable
1 parent 8631aa6 commit c64ff0d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ Turbo mode:
3434
from random import sample
3535
from timeit import timeit
3636
37-
from sonyflake_turbo import SONYFLAKE_MACHINE_ID_MAX, SonyFlake
37+
from sonyflake_turbo import SONYFLAKE_MACHINE_ID_MAX, MachineIDLCG, SonyFlake
3838
39+
get_machine_id = MachineIDLCG(int(datetime.now(tz=timezone.utc).timestamp()))
3940
epoch = datetime(2025, 6, 5, tzinfo=timezone.utc)
4041
4142
for count in [32, 16, 8, 4, 2, 1]:

sonyflake_turbo.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ static PyObject *machine_id_lcg_next(struct machine_id_lcg_state *self) {
357357
return PyLong_FromLong(machine_id_lcg_atomic(&self->machine_id));
358358
}
359359

360+
static PyObject *machine_id_lcg_call(struct machine_id_lcg_state *self, PyObject *args, PyObject *kwargs) {
361+
return machine_id_lcg_next(self);
362+
}
363+
360364
PyDoc_STRVAR(machine_id_lcg_doc,
361365
"MachineIDLCG(seed, /)\n--\n\n"
362366
"LCG with params a=32309, c=13799, m=65536.\n"
@@ -370,6 +374,7 @@ static PyType_Slot machine_id_lcg_slots[] = {
370374
{Py_tp_iter, PyObject_SelfIter},
371375
{Py_tp_iternext, machine_id_lcg_next},
372376
{Py_tp_new, machine_id_lcg_new},
377+
{Py_tp_call, machine_id_lcg_call},
373378
{Py_tp_doc, machine_id_lcg_doc},
374379
{0, 0},
375380
};

0 commit comments

Comments
 (0)