Accept the indexing pool from which numbers are selected and returned.
Accept the indexing pool from which numbers are selected and returned.
Correct its format to suit the current NumberSelector
algorithms.
Moving all of the invalid negative-ones (-1) to the left of the current valid indices works for most selectors.
The selectionIndex
is set to the first valid number available from the left.
The ret
index is set to index zero.
the Array
of Int
numbers
Accept a provided pool
and select the next number.
...
Accept a provided pool
and select the next number.
...
the Array
of Int
numbers from which to draw a new number
an Int
number
Give a number back to a specific collection following the principles of this selector.
The number is always returned to a "used" index position near the front of the array.
Give a number back to a specific collection following the principles of this selector.
The number is always returned to a "used" index position near the front of the array.
It locates this position by incrementally traversing the Array
behind the position used in Get
.
Asides from selection, a disorderly reinsertion of numbers back into the pool is also a source of randomness.
the number to be returned
the Array
of Int
numbers to which the number is to be returned
true
, if this return was successful; false
, otherwise
The index for the selector when performing a number return action, then modified for the "next" index.
The index for the selector when performing a number return action, then modified for the "next" index.
The index for the selector when performing a number selection action, then modified to the "next" index.
The index for the selector when performing a number selection action, then modified to the "next" index.
Get a pseudorandom number from a pool of numbers. The contained logic is similar to
RandomSequenceSelector
. It is not reliant of a shrinking pool that composes into some sequence of all the numbers, however; the numbers are re-introduced to the selection as long as the pool is used. This allows for the sequence to contain repeat numbers far before ever visiting all of the numbers once.During the selection process:
The index is the position from where the selection begins, and the end of the
Array
is where the selection ends. Once a position between those two indices is selected, that number is extracted. The number at the start position is swapped into the position where the selection number was extracted. The start position is then set to an invalid number, and the start index is advanced. Repeat next request.During the return process:
The returned number is added to the input
Array
at the position just before the current selection position. The selection index is then reversedback to re-include the returned number. The normal return index is not used in this algorithm.RandomSequenceSelector