object Random extends Random
The object Random
offers a default implementation
of scala.util.Random and random-related convenience methods.
- Source
- Random.scala
- Alphabetic
- By Inheritance
- Random
- Random
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- def alphanumeric: collection.immutable.LazyList[Char]
Returns a LazyList of pseudorandomly chosen alphanumeric characters, equally chosen from A-Z, a-z, and 0-9.
Returns a LazyList of pseudorandomly chosen alphanumeric characters, equally chosen from A-Z, a-z, and 0-9.
- Definition Classes
- Random
- Annotations
- @migration
- Migration
(Changed in version 2.13.0)
alphanumeric
returns a LazyList instead of a Stream
- def between(minInclusive: Long, maxExclusive: Long): Long
Returns a pseudorandom, uniformly distributed long value between min (inclusive) and the specified value max (exclusive), drawn from this random number generator's sequence.
Returns a pseudorandom, uniformly distributed long value between min (inclusive) and the specified value max (exclusive), drawn from this random number generator's sequence.
- Definition Classes
- Random
- def between(minInclusive: Int, maxExclusive: Int): Int
Returns a pseudorandom, uniformly distributed int value between min (inclusive) and the specified value max (exclusive), drawn from this random number generator's sequence.
Returns a pseudorandom, uniformly distributed int value between min (inclusive) and the specified value max (exclusive), drawn from this random number generator's sequence.
- Definition Classes
- Random
- def between(minInclusive: Float, maxExclusive: Float): Float
Returns the next pseudorandom, uniformly distributed float value between min (inclusive) and max (exclusive) from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed float value between min (inclusive) and max (exclusive) from this random number generator's sequence.
- Definition Classes
- Random
- def between(minInclusive: Double, maxExclusive: Double): Double
Returns the next pseudorandom, uniformly distributed double value between min (inclusive) and max (exclusive) from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed double value between min (inclusive) and max (exclusive) from this random number generator's sequence.
- Definition Classes
- Random
- implicit def javaRandomToRandom(r: java.util.Random): Random
- def nextBoolean(): Boolean
Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
- Definition Classes
- Random
- def nextBytes(n: Int): Array[Byte]
Generates
n
random bytes and returns them in a new array.Generates
n
random bytes and returns them in a new array.- Definition Classes
- Random
- def nextBytes(bytes: Array[Byte]): Unit
Generates random bytes and places them into a user-supplied byte array.
Generates random bytes and places them into a user-supplied byte array.
- Definition Classes
- Random
- def nextDouble(): Double
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
- Definition Classes
- Random
- def nextFloat(): Float
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
- Definition Classes
- Random
- def nextGaussian(): Double
Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
- Definition Classes
- Random
- def nextInt(n: Int): Int
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
- Definition Classes
- Random
- def nextInt(): Int
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
- Definition Classes
- Random
- def nextLong(n: Long): Long
Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
- Definition Classes
- Random
- def nextLong(): Long
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
- Definition Classes
- Random
- def nextPrintableChar(): Char
Returns the next pseudorandom, uniformly distributed value from the ASCII range 33-126.
Returns the next pseudorandom, uniformly distributed value from the ASCII range 33-126.
- Definition Classes
- Random
- def nextString(length: Int): String
Returns a pseudorandomly generated String.
Returns a pseudorandomly generated String. This routine does not take any measures to preserve the randomness of the distribution in the face of factors like unicode's variable-length encoding, so please don't use this for anything important. It's primarily intended for generating test data.
- length
the desired length of the String
- returns
the String
- Definition Classes
- Random
- val self: java.util.Random
- Definition Classes
- Random
- def setSeed(seed: Long): Unit
- Definition Classes
- Random
- def shuffle[T, C](xs: IterableOnce[T])(implicit bf: BuildFrom[xs.type, T, C]): C
Returns a new collection of the same type in a randomly chosen order.
Returns a new collection of the same type in a randomly chosen order.
- returns
the shuffled collection
- Definition Classes
- Random
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.collection.parallel
- Parallel collections (scala-parallel-collections.jar)scala.util.parsing
- Parser combinators (scala-parser-combinators.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.