Generic Instance Method 総称体インスタンスメソッド

shuffled(using:)

Returns the elements of the sequence, shuffled using the given generator as a source for randomness. シーケンスの要素を返します、与えられた生成子を無作為さの源として使ってシャッフルされます。

Declaration 宣言

func shuffled<T>(using generator: inout T) -> [UInt8] where T : RandomNumberGenerator

Parameters パラメータ

generator

The random number generator to use when shuffling the sequence. シーケンスをシャッフルする時に使う乱数生成子。

Return Value 戻り値

An array of this sequence’s elements in a shuffled order. シャッフルされた順番でのこのシーケンスのもつ要素からなる配列。

Discussion 議論

You use this method to randomize the elements of a sequence when you are using a custom random number generator. For example, you can shuffle the numbers between 0 and 9 by calling the shuffled(using:) method on that range: あなたは、あなたがあつらえの乱数生成子を使っている時このメソッドを使ってシーケンスの要素をランダム化します。例えば、あなたは09の間の数をシャッフルすることが、shuffled(using:)メソッドをその範囲上で呼び出すことによって可能です:


let numbers = 0...9
let shuffledNumbers = numbers.shuffled(using: &myGenerator)
// shuffledNumbers == [8, 9, 4, 3, 2, 6, 7, 0, 5, 1]

Complexity: O(n), where n is the length of the sequence. 計算量:O(n)、ここでnはシーケンスの長さです。