Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

perl

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

like image 468
yildizabdullah Avatar asked Nov 11 '15 10:11

yildizabdullah


1 Answers

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.

like image 99
LeoNerd Avatar answered Nov 15 '22 16:11

LeoNerd