How to do List :: Util 'shuffle' reproduces the same result in Perl

Is it possible to use Perl shuffle so that every time it produces outputs in the same order?

+4
source share
1 answer

Use the function srand()always with the same initial value ( 123in this case). For example. I get:

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

repeated every time. Without srand (), calling it is different.

+9
source

Source: https://habr.com/ru/post/1615384/


All Articles