First working implementation of the genid method
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import random
|
||||
|
||||
from dataclass_persistence import Persistent
|
||||
from dataclasses import dataclass, field
|
||||
from typing import ClassVar
|
||||
@@ -72,7 +74,18 @@ class Minter(Persistent):
|
||||
# - value + (index * percounter)
|
||||
# - mask
|
||||
# 10. return the noid
|
||||
return ""
|
||||
if self.oacounter >= self.oatop:
|
||||
raise Exception("noid are exhausted.")
|
||||
s = len(self.active_counters)
|
||||
if s < 1:
|
||||
raise Exception("noid are exhausted.")
|
||||
idx = random.randrange(s)
|
||||
c = self.active_counters[idx]
|
||||
c.value += 1
|
||||
self.oacounter += 1
|
||||
if c.value >= c.top:
|
||||
self.active_counters.pop(idx)
|
||||
return self._n2xdig(c.value + (c.rank * self.percounter))
|
||||
|
||||
def initcounters(self) -> None:
|
||||
# 1. [X] Initialize oacounter to 0
|
||||
|
||||
Reference in New Issue
Block a user