class RandomSequenceSelector extends NumberSelector
Get a pseudorandom number from a pool of numbers.
The output of this class, operating on an Array
of Int
values is contained to some sequence of all the numbers.
Only after every number is selected once, may any number repeat.
The pseudorandomness of any sequence of numbers is not only provided by an internal system Random
but by the order or returned numbers.
Consequentially, as any single sequence nears completion, the numbers remaining become more and more predictable.
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.
The return index trails behind the selection index as far as the order of the array is concerned at first.
After some time, the selection index moves to the starting position of the array again and then the order is reversed.
Until the return index wraps around to the beginning of the array too, it is considered the valid selection end position.
During the return process:
As the Array
empties out from the first to the last index, the return process starts at the first index again.
When a number is "returned," it is placed back into the input Array
at the earliest available index.
The return index is advanced.
Neither the selection index nor the return index may pass each other,
except when one reaches the end of the Array
and wraps back around to that start.
- Source
- RandomSequenceSelector.scala
- See also
RandomSelector
- Alphabetic
- By Inheritance
- RandomSequenceSelector
- NumberSelector
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new RandomSequenceSelector()
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def Format(ary: Array[Int]): Unit
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. TheselectionIndex
is set to the first valid number available from the left. Theret
index is set to index zero.- ary
the
Array
ofInt
numbers
- Definition Classes
- NumberSelector
- def Get(ary: Array[Int]): Int
Accept a provided "pool of numbers" and select the next number.
Accept a provided "pool of numbers" and select the next number.
- ary
the
Array
ofInt
numbers from which to draw a new number- returns
an
Int
number
- Definition Classes
- RandomSequenceSelector → NumberSelector
- def Return(number: Int, ary: Array[Int]): Boolean
Give a number back to a specific collection following the principles of this selector.
Give a number back to a specific collection following the principles of this selector.
- number
the number to be returned
- ary
the
Array
ofInt
numbers to which the number is to be returned- returns
true
, if this return was successful;false
, otherwise
- Definition Classes
- RandomSequenceSelector → NumberSelector
- def ReturnIndex: Int
- Definition Classes
- NumberSelector
- def SelectionIndex: Int
- Definition Classes
- NumberSelector
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- var ret: Int
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.
- Attributes
- protected
- Definition Classes
- NumberSelector
- var selectionIndex: Int
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.
- Attributes
- protected
- Definition Classes
- NumberSelector
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()