Generic Type Method

random(in:using:)

Returns a random value within the specified range, using the given generator as a source for randomness. 指定された範囲内のある無作為な値を返します、与えられた生成子を無作為さの出典として使って使います。

Declaration 宣言

static func random<T>(in range: Range<Float>, using generator: inout T) -> Float where T : RandomNumberGenerator

Parameters パラメータ

range

The range in which to create a random value. range must be finite and non-empty. その中においてある無作為な値が作成される範囲。rangeは有限でそして空でない必要があります。

generator

The random number generator to use when creating the new random value. 新しい無作為値を作成するときに使う無作為数生成子。

Return Value 戻り値

A random value within the bounds of range. rangeの境界内のある無作為な値。

Discussion 解説

Use this method to generate a floating-point value within a specific range when you are using a custom random number generator. This example creates three new values in the range 10.0 ..< 20.0. このメソッドを使って、あなたがあつらえの無作為数生成子を使っている場合に、特定の範囲の内のある浮動小数点値を作成してください。この例は、3つの新しい値を範囲10.0 ..< 20.0において作成します。


for _ in 1...3 {
    print(Double.random(in: 10.0 ..< 20.0, using: &myGenerator))
}
// Prints "18.1900709259179"
// Prints "14.2286325689993"
// Prints "13.1485686260762"

The random(in:using:) static method chooses a random value from a continuous uniform distribution in range, and then converts that value to the nearest representable value in this type. Depending on the size and span of range, some concrete values may be represented more frequently than others. random(in:using:)静的メソッドは無作為の値をrangeの中の連続一様分布から選びます、それからその値をその型で表現可能な最も近い値に変換します。rangeの大きさと幅に依存して、いくつかの具体的な値は他のものよりずっと頻繁に表現されるかもしれません。

See Also 参照

Creating a Random Value 無作為な値を作成する