Instance Method インスタンスメソッド

shuffled()

Returns the elements of the sequence, shuffled. 入れ替えた、シーケンスの要素を返します。

Declaration 宣言

func shuffled() -> [Element]

Return Value 戻り値

A shuffled array of this sequence’s elements. このシーケンスの持つ要素からなる、あるシャッフルされた配列。

Discussion 解説

For example, you can shuffle the numbers between 0 and 9 by calling the shuffled() method on that range: 例えば、あなたは09の間の数をシャッフルすることが、shuffled()メソッドをその範囲上で呼び出すことによって可能です:


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

This method is equivalent to calling shuffled(using:), passing in the system’s default random generator. このメソッドは、shuffled(using:)を、システムの持つ省略時の無作為生成子を渡して呼び出すことに相当します。

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

See Also 参照

Reordering an Array's Elements 配列の要素を再配列します