# Shuffling a dictionary similar to an array

**URL:** <https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977>\
**Category:** Swift Apprentice\
**Created:** [January 17, 2019, 2:34am UTC](https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977 "2019-01-17T02:34:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpalme](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dpalme/32/102075_2.png) [@dpalme](https://forums.kodeco.com/u/dpalme)\
**Post date:** [January 17, 2019, 2:34am UTC](https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977/1 "2019-01-17T02:34:21Z")

</div>

Is there a way to shuffle a dictionary similar to the way we can shuffle an array?

---

<div class="post-metadata">

**Author:** ![sgerrard](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sgerrard/32/93812_2.png) [@sgerrard](https://forums.kodeco.com/u/sgerrard)\
**Post date:** [January 17, 2019, 10:33pm UTC](https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977/2 "2019-01-17T22:33:41Z")

</div>

Not directly, because a dictionary is stored as a hash table.  
You can make a copy of the keys as an array, though, and sort or shuffle that. You can use that to retrieve the dictionary entries in the order of the keys in the copy.

---

<div class="post-metadata">

**Author:** ![dpalme](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/dpalme/32/102075_2.png) [@dpalme](https://forums.kodeco.com/u/dpalme)\
**Post date:** [January 24, 2019, 3:31pm UTC](https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977/3 "2019-01-24T15:31:27Z")

</div>

Thanks, I was able to add a line to move its values to an array and then shuffled before reading it out as the dictionary. I hope that makes sense.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [July 2, 2019, 6:34pm UTC](https://forums.kodeco.com/t/shuffling-a-dictionary-similar-to-an-array/59977/4 "2019-07-02T18:34:22Z")

</div>

Closed on July 2, 2019, 6:34pm UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
