tinyscalautils.util

Members list

Type members

Classlikes

class FastRandom extends Random

Fast (but not thread-safe) random number generator.

Fast (but not thread-safe) random number generator.

The implementation relies on SplittableRandom. Java's fancier generators are not used.

The generator is always seeded. If an unseeded generator is needed, use the FastGenerator object directly; it can be shared harmlessly throughout an application (including across threads).

Attributes

Note

The generator returned by self is ''not'' thread-safe, even though it subclasses java.util.Random.

Companion
object
Source
FastRandom.scala
Supertypes
class Random
trait Serializable
class Object
trait Matchable
class Any
Known subtypes
object FastRandom
object FastRandom extends FastRandom

A thread-safe, unseeded fast random number generator.

A thread-safe, unseeded fast random number generator.

The implementation relies on ThreadLocalRandom, which can be shared across threads without contention. Java's fancier generators are not used.

This generator cannot be re-seeded (the setSeed method throws UnsupportedOperationException).

Attributes

Companion
class
Source
FastRandom.scala
Supertypes
class FastRandom
class Random
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
FastRandom.type

Value members

Concrete methods

def average[A](seq: Seq[A], ignoredPairs: Int)(using evidence$1: Fractional[A]): A

Calculates an average by ignoring a fixed number of low/high values. The number is specified as a number of ''pairs'' lowest/highest values.

Calculates an average by ignoring a fixed number of low/high values. The number is specified as a number of ''pairs'' lowest/highest values.

This function returns 0 if the sequence is empty, or all the numbers are ignored.

Attributes

Source
average.scala
def log2(n: Int): Int

The largest integer m such that 2^m <= n.

The largest integer m such that 2^m <= n.

Attributes

Throws
IllegalArgumentException

if n is not positive.

Source
log2.scala
def log2(n: Long): Int

The largest integer m such that 2^m <= n.

The largest integer m such that 2^m <= n.

Attributes

Throws
IllegalArgumentException

if n is not positive.

Source
log2.scala

Extensions

Extensions

extension (n: Int)

True iff an integer is even.

True iff an integer is even.

Attributes

Source
evenOdd.scala
def isOdd: Boolean

True iff an integer is odd.

True iff an integer is odd.

Attributes

Source
evenOdd.scala
extension [Num](n: Num)(using evidence$1: Numeric[Num])
inline def isZero: Boolean

Test that a number is zero.

Test that a number is zero.

Attributes

Source
isZero.scala
extension [A](n: A)(using evidence$1: Numeric[A])
def pow(m: Int): A

Calculates the interger power of a number.

Calculates the interger power of a number.

Attributes

Throws
IllegalArgumentException

if the power is negative.

Since

1.5.0

Note

This function does not check for overflows; it also return 1 when m is 0, even if n is zero.

Source
pow.scala
extension (n: Long)

True iff an integer is even.

True iff an integer is even.

Attributes

Source
evenOdd.scala
def isOdd: Boolean

True iff an integer is odd.

True iff an integer is odd.

Attributes

Source
evenOdd.scala
extension (rand: Random)
def nextInt(range: Range): Int

Adds a Kotlin-like nextInt method to random number generators. This method enables calls of the form rand.nextInt(1 to 100).

Adds a Kotlin-like nextInt method to random number generators. This method enables calls of the form rand.nextInt(1 to 100).

This method is only defined for ranges. For a more general sequence of integers, use pickOne instead.

Range argument cannot be empty.

Attributes

Source
randomRange.scala
extension (rand: Random)

A wrapper that calls all the Random methods interruptibly. The new generator is as thread-safe as the original.

A wrapper that calls all the Random methods interruptibly. The new generator is as thread-safe as the original.

Attributes

Source
FastRandom.scala