Undo shuffle

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.

Store the array before you shuffle it.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs