# Undo shuffle

**URL:** <https://www.ruby-forum.com/t/undo-shuffle/236940>\
**Category:** Ruby\
**Created:** [October 12, 2013, 6:15pm UTC](https://www.ruby-forum.com/t/undo-shuffle/236940 "2013-10-12T18:15:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [October 12, 2013, 6:15pm UTC](https://www.ruby-forum.com/t/undo-shuffle/236940/1 "2013-10-12T18:15:16Z")

</div>

Hi,

with this code I always get the same result  
ary = [1,2,3,4,5,6,7,8,9,0]  
number = 8  
ary.shuffle!(random: Random.new(number))  
#=\> ary = [9, 7, 0, 1, 3, 6, 8, 2, 5, 4]

That is what I want, but is there anything how I can undo this so that:  
ary.shuffle!(something)  
so that  
#=\> ary = [1,2,3,4,5,6,7,8,9,0]

I have tried some things but they all do not work.

I am looking forward to hear from you.

King regards  
Green E.

---

<div class="post-metadata">

**Author:** ![greeneco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@greeneco](https://www.ruby-forum.com/u/greeneco)\
**Post date:** [October 12, 2013, 6:24pm UTC](https://www.ruby-forum.com/t/undo-shuffle/236940/2 "2013-10-12T18:24:56Z")

</div>

Store the array before you shuffle it.

---

<div class="post-metadata">

**Author:** ![greeneco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/3bc359/32.png) [@greeneco](https://www.ruby-forum.com/u/greeneco)\
**Post date:** [October 13, 2013, 12:11am UTC](https://www.ruby-forum.com/t/undo-shuffle/236940/3 "2013-10-13T00:11:30Z")

</div>

Am 12.10.2013 18:15, schrieb Green E.:

> with this code I always get the same result  
> ary = [1,2,3,4,5,6,7,8,9,0]  
> number = 8  
> ary.shuffle!(random: Random.new(number))  
> #=\> ary = [9, 7, 0, 1, 3, 6, 8, 2, 5, 4]
> 
> That is what I want, but is there anything how I can undo this so that:  
> ary.shuffle!(something)  
> so that  
> #=\> ary = [1,2,3,4,5,6,7,8,9,0]

Use the non-bang version of shuffle:

array = [1,2,3,4,5,6,7,8,9,0]  
seed = 8  
shuffled\_array = array.shuffle(random: Random.new(seed))

Then `array’ won’t be modified.

Regards,  
Marcus
