trice
trice copied to clipboard
Improve ID random generation
Currently new IDs are randomly generated and afterwards checked, if already used. If, the process starts again. That works fine as long the used ID amount is small. A better approach is, to select randomly from the so far unused IDs.
Joinedxwith #260
Remove "alredy used" message
An init() function should create a uint16 slice with len IDmax - IDmin and fill it iteratively with IDmin....IDmax. Any used ID is swapped to the slice[used] with used++. For a new random ID r use interval [0, len - used]. Then swap slice[used] and slice[used+r], used++ and return original slice[used+r].
If IDs exist outside IDmin...IDmax, they are ignored. If such a trice changed, simply a new ID is generated.
Done in trice insert
from v0.61.0