Packages

trait TestRandom extends Random with Restorable

TestRandom allows for deterministically testing effects involving randomness.

TestRandom operates in two modes. In the first mode, TestRandom is a purely functional pseudo-random number generator. It will generate pseudo-random values just like scala.util.Random except that no internal state is mutated. Instead, methods like nextInt describe state transitions from one random state to another that are automatically composed together through methods like flatMap. The random seed can be set using setSeed and TestRandom is guaranteed to return the same sequence of values for any given seed. This is useful for deterministically generating a sequence of pseudo-random values and powers the property based testing functionality in ZIO Test.

In the second mode, TestRandom maintains an internal buffer of values that can be "fed" with methods such as feedInts and then when random values of that type are generated they will first be taken from the buffer. This is useful for verifying that functions produce the expected output for a given sequence of "random" inputs.

import zio.Random
import zio.test.TestRandom

for {
  _ <- TestRandom.feedInts(4, 5, 2)
  x <- Random.nextIntBounded(6)
  y <- Random.nextIntBounded(6)
  z <- Random.nextIntBounded(6)
} yield x + y + z == 11

TestRandom will automatically take values from the buffer if a value of the appropriate type is available and otherwise generate a pseudo-random value, so there is nothing you need to do to switch between the two modes. Just generate random values as you normally would to get pseudo-random values, or feed in values of your own to get those values back. You can also use methods like clearInts to clear the buffer of values of a given type so you can fill the buffer with new values or go back to pseudo-random number generation.

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. TestRandom
  2. Restorable
  3. Random
  4. Serializable
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. trait UnsafeAPI extends AnyRef
    Definition Classes
    Random

Abstract Value Members

  1. abstract def clearBooleans(implicit trace: Trace): UIO[Unit]
  2. abstract def clearBytes(implicit trace: Trace): UIO[Unit]
  3. abstract def clearChars(implicit trace: Trace): UIO[Unit]
  4. abstract def clearDoubles(implicit trace: Trace): UIO[Unit]
  5. abstract def clearFloats(implicit trace: Trace): UIO[Unit]
  6. abstract def clearInts(implicit trace: Trace): UIO[Unit]
  7. abstract def clearLongs(implicit trace: Trace): UIO[Unit]
  8. abstract def clearStrings(implicit trace: Trace): UIO[Unit]
  9. abstract def clearUUIDs(implicit trace: Trace): UIO[Unit]
  10. abstract def feedBooleans(booleans: Boolean*)(implicit trace: Trace): UIO[Unit]
  11. abstract def feedBytes(bytes: Chunk[Byte]*)(implicit trace: Trace): UIO[Unit]
  12. abstract def feedChars(chars: Char*)(implicit trace: Trace): UIO[Unit]
  13. abstract def feedDoubles(doubles: Double*)(implicit trace: Trace): UIO[Unit]
  14. abstract def feedFloats(floats: Float*)(implicit trace: Trace): UIO[Unit]
  15. abstract def feedInts(ints: Int*)(implicit trace: Trace): UIO[Unit]
  16. abstract def feedLongs(longs: Long*)(implicit trace: Trace): UIO[Unit]
  17. abstract def feedStrings(strings: String*)(implicit trace: Trace): UIO[Unit]
  18. abstract def feedUUIDs(UUIDs: UUID*)(implicit trace: Trace): UIO[Unit]
  19. abstract def getSeed(implicit trace: Trace): UIO[Long]
  20. abstract def nextBoolean(implicit trace: Trace): UIO[Boolean]
    Definition Classes
    Random
  21. abstract def nextBytes(length: => Int)(implicit trace: Trace): UIO[Chunk[Byte]]
    Definition Classes
    Random
  22. abstract def nextDouble(implicit trace: Trace): UIO[Double]
    Definition Classes
    Random
  23. abstract def nextDoubleBetween(minInclusive: => Double, maxExclusive: => Double)(implicit trace: Trace): UIO[Double]
    Definition Classes
    Random
  24. abstract def nextFloat(implicit trace: Trace): UIO[Float]
    Definition Classes
    Random
  25. abstract def nextFloatBetween(minInclusive: => Float, maxExclusive: => Float)(implicit trace: Trace): UIO[Float]
    Definition Classes
    Random
  26. abstract def nextGaussian(implicit trace: Trace): UIO[Double]
    Definition Classes
    Random
  27. abstract def nextInt(implicit trace: Trace): UIO[Int]
    Definition Classes
    Random
  28. abstract def nextIntBetween(minInclusive: => Int, maxExclusive: => Int)(implicit trace: Trace): UIO[Int]
    Definition Classes
    Random
  29. abstract def nextIntBounded(n: => Int)(implicit trace: Trace): UIO[Int]
    Definition Classes
    Random
  30. abstract def nextLong(implicit trace: Trace): UIO[Long]
    Definition Classes
    Random
  31. abstract def nextLongBetween(minInclusive: => Long, maxExclusive: => Long)(implicit trace: Trace): UIO[Long]
    Definition Classes
    Random
  32. abstract def nextLongBounded(n: => Long)(implicit trace: Trace): UIO[Long]
    Definition Classes
    Random
  33. abstract def nextPrintableChar(implicit trace: Trace): UIO[Char]
    Definition Classes
    Random
  34. abstract def nextString(length: => Int)(implicit trace: Trace): UIO[String]
    Definition Classes
    Random
  35. abstract def nextUUID(implicit trace: Trace): UIO[UUID]
    Definition Classes
    Random
  36. abstract def save(implicit trace: Trace): UIO[UIO[Unit]]
    Definition Classes
    Restorable
  37. abstract def setSeed(seed: => Long)(implicit trace: Trace): UIO[Unit]
    Definition Classes
    TestRandomRandom
  38. abstract def shuffle[A, Collection[+Element] <: Iterable[Element]](collection: => Collection[A])(implicit bf: zio.BuildFrom[Collection[A], A, Collection[A]], trace: Trace): UIO[Collection[A]]
    Definition Classes
    Random

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  9. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  10. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  11. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  13. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  14. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  15. def toString(): String
    Definition Classes
    AnyRef → Any
  16. def unsafe: UnsafeAPI
    Definition Classes
    Random
  17. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  18. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from Restorable

Inherited from Random

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped