trice icon indicating copy to clipboard operation
trice copied to clipboard

Improve ID random generation

Open rokath opened this issue 2 years ago • 2 comments

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.

rokath avatar Jan 03 '22 10:01 rokath

Joinedxwith #260

rokath avatar May 21 '22 10:05 rokath

Remove "alredy used" message

rokath avatar Aug 29 '22 03:08 rokath

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].

rokath avatar Feb 13 '23 23:02 rokath

If IDs exist outside IDmin...IDmax, they are ignored. If such a trice changed, simply a new ID is generated.

rokath avatar Feb 14 '23 21:02 rokath

Done in trice insert from v0.61.0

rokath avatar Jul 24 '23 11:07 rokath