implicit final class ApsoRandom extends AnyVal
Implicit class that provides new methods for random number generators.
- Alphabetic
- By Inheritance
- ApsoRandom
- AnyVal
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
-
new
ApsoRandom(rand: Random)
- rand
the
Randominstance to which the new methods are provided.
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
##(): Int
- Definition Classes
- Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
choose[T](seq: IndexedSeq[T]): Option[T]
Chooses a random element from an indexed sequence.
Chooses a random element from an indexed sequence.
- T
the type of the elements
- seq
the indexed sequence of elements to choose from
- returns
the selected element wrapped in a
Someifseqhas at least one element,Noneotherwise.
-
def
chooseN[T](seq: Seq[T], n: Int): Seq[T]
Chooses n random element from a sequence.
Chooses n random element from a sequence.
- T
the type of the elements
- seq
the sequence of elements to choose from
- returns
the selected elements
-
def
decreasingUniformStream(n: Int): Stream[Double]
Returns a decreasingly ordered stream of n doubles in [0, 1], according to a uniform distribution.
Returns a decreasingly ordered stream of n doubles in [0, 1], according to a uniform distribution. More Info: BENTLEY, SAXE, Generating Sorted Lists of Random Numbers
- n
amount of numbers to generate
- returns
ordered stream of doubles
-
def
getClass(): Class[_ <: AnyVal]
- Definition Classes
- AnyVal → Any
-
def
increasingUniformStream(n: Int): Stream[Double]
Returns an increasingly ordered stream of n doubles in [0, 1], according to a uniform distribution.
Returns an increasingly ordered stream of n doubles in [0, 1], according to a uniform distribution. More Info: BENTLEY, SAXE, Generating Sorted Lists of Random Numbers
- n
amount of numbers to generate
- returns
ordered stream of doubles
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
monteCarlo[T](seq: Traversable[(T, Double)], r: Double = rand.nextDouble()): Option[T]
Chooses an element of a sequence according to a weight function.
Chooses an element of a sequence according to a weight function.
- T
the type of the elements in the sequence
- seq
the pairs (element, probability) to choose from
- returns
the selected element wrapped in a
Someif some element was chosen,Noneotherwise. Not choosing any element can happen if the weights of the elements do not sum up to the maximum value ofr.
- Annotations
- @inline()
-
def
monteCarlo[T](seq: Traversable[T], valueFunc: (T) ⇒ Double, r: Double): Option[T]
Chooses an element of a sequence according to a weight function.
Chooses an element of a sequence according to a weight function.
- T
the type of the elements
- seq
the elements to choose from
- valueFunc
the function that maps elements to weights
- r
the random value used to select the elements. If the default random value is used, the weighted selection uses 1.0 as the sum of all weights. To use another scale of weights, a random value between 0.0 and the maximum weight should be passed.
- returns
the selected element wrapped in a
Someif some element was chosen,Noneotherwise. Not choosing any element can happen if the weights of the elements do not sum up to the maximum value ofr.
- val rand: Random
-
def
reservoirSample[T](seq: TraversableOnce[T]): Option[T]
Chooses a random element of a traversable using the reservoir sampling technique, traversing only once the given sequence.
Chooses a random element of a traversable using the reservoir sampling technique, traversing only once the given sequence.
- T
the type of the elements
- seq
the elements to choose from
- returns
the selected element wrapped in a
Some, orNoneif the traversable is empty.
-
def
samples[T](seq: Traversable[(T, Double)]): Iterator[T]
Returns an infinite stream of weighted samples of a sequence.
Returns an infinite stream of weighted samples of a sequence.
- T
the type of the elements
- seq
the pairs (element, probability) to choose from
- returns
an infinite stream of weighted samples of a sequence.
- Annotations
- @inline()
-
def
samples[T](seq: Traversable[T], valueFunc: (T) ⇒ Double): Iterator[T]
Returns an infinite stream of weighted samples of a sequence.
Returns an infinite stream of weighted samples of a sequence.
- T
the type of the elements
- seq
the elements to choose from
- returns
an infinite stream of weighted samples of a sequence.
-
def
toString(): String
- Definition Classes
- Any