yildizabdullah
yildizabdullah

Reputation: 1971

How to make List::Util 'shuffle' reproduce same output in Perl

Can Perl's shuffle be utilized such that each time it produces the outputs in the same order?

Upvotes: 5

Views: 743

Answers (1)

LeoNerd
LeoNerd

Reputation: 8532

Use the srand() function always with the same seed value (123 in this case). E.g. I get:

$ perl -MList::Util=shuffle -E 'srand 123; say shuffle 1 .. 5'
41352

repeatable every time. Without the srand() call it differs.

Upvotes: 10

Related Questions