<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, randperm in MapleTA produces always the same permutation</title>
    <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 06:51:37 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 06:51:37 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, randperm in MapleTA produces always the same permutation</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, randperm in MapleTA produces always the same permutation</title>
      <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always</link>
    </image>
    <item>
      <title>Get a new seed for the pseudo-random number generator.</title>
      <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always?ref=Feed:MaplePrimes:randperm in MapleTA produces always the same permutation:Comments#answer140451</link>
      <itunes:summary>&lt;p&gt;Maple always starts with the same seed for its pseudo-random number generator.&amp;nbsp; What you need to do is to get new seed.&amp;nbsp; For example, you could use, in MapleTA,&lt;/p&gt;
&lt;p&gt;$seed=rand(1000,10000000);&lt;/p&gt;
&lt;p&gt;to get a seed and then use&lt;/p&gt;
&lt;p&gt;RandomTools[SetState](state=$seed);&lt;/p&gt;
&lt;p&gt;within your maple code to get different permutations.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $n=3;&lt;br&gt;      $seed=rand(1000,10000000);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pa=maple("randomize();with(combinat);RandomTools[SetState](state=$seed);[randperm($n),randperm($n)]");&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;Maple always starts with the same seed for its pseudo-random number generator.&amp;nbsp; What you need to do is to get new seed.&amp;nbsp; For example, you could use, in MapleTA,&lt;/p&gt;
&lt;p&gt;$seed=rand(1000,10000000);&lt;/p&gt;
&lt;p&gt;to get a seed and then use&lt;/p&gt;
&lt;p&gt;RandomTools[SetState](state=$seed);&lt;/p&gt;
&lt;p&gt;within your maple code to get different permutations.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $n=3;&lt;br&gt;      $seed=rand(1000,10000000);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pa=maple("randomize();with(combinat);RandomTools[SetState](state=$seed);[randperm($n),randperm($n)]");&lt;/pre&gt;</description>
      <guid>140451</guid>
      <pubDate>Fri, 16 Nov 2012 23:05:58 Z</pubDate>
      <itunes:author>jaytreiman</itunes:author>
      <author>jaytreiman</author>
    </item>
    <item>
      <title>StringTools</title>
      <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always?ref=Feed:MaplePrimes:randperm in MapleTA produces always the same permutation:Comments#answer140541</link>
      <itunes:summary>&lt;p&gt;I just found out the following piece of information. The combinat:-randperm command of Maple 16 makes an external call to a function in the {lib}mstring.{so,dll} shared library.&lt;/p&gt;
&lt;pre&gt;&amp;gt; showstat((combinat::Permutations)::Random);

(combinat::Permutations):-Random := proc()
   1   passign(procname,subsop(5 = "generate a random permutation",defun(convert(mstring_randperm,'string'),"mstring",(':-mtsafe') = true)));
   2   procname(args)
end proc
&lt;/pre&gt;
&lt;p&gt;And it turns out the the seed for this is controlled by the StringTools:-Randomize command.&lt;/p&gt;
&lt;p&gt;The following is done in the commandline interface of 64bit Maple 16.01 on Linux. The behavior seems similar in Maple 14.01 and 15.01.&lt;/p&gt;
&lt;pre&gt;&amp;gt; restart:          
&amp;gt; with(combinat):   
&amp;gt; L:=[1,2,3]:       
&amp;gt; randperm(L), randperm(L);

                             [2, 1, 3], [1, 3, 2]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; L:=[1,2,3]:              
&amp;gt; randperm(L), randperm(L);

                             [2, 1, 3], [1, 3, 2]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; StringTools:-Randomize():
&amp;gt; L:=[1,2,3]:
&amp;gt; randperm(L), randperm(L);

                             [1, 2, 3], [3, 2, 1]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; StringTools:-Randomize():
&amp;gt; L:=[1,2,3]:              
&amp;gt; randperm(L), randperm(L);

                             [3, 1, 2], [2, 1, 3]
&lt;/pre&gt;
&lt;p&gt;Of course, this might be better handled in a centralized location (ie. the `randomize` command, and/or RandomTools package).&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;Dave Linder&lt;br&gt; Mathematical Software, Maplesoft&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I just found out the following piece of information. The combinat:-randperm command of Maple 16 makes an external call to a function in the {lib}mstring.{so,dll} shared library.&lt;/p&gt;
&lt;pre&gt;&amp;gt; showstat((combinat::Permutations)::Random);

(combinat::Permutations):-Random := proc()
   1   passign(procname,subsop(5 = "generate a random permutation",defun(convert(mstring_randperm,'string'),"mstring",(':-mtsafe') = true)));
   2   procname(args)
end proc
&lt;/pre&gt;
&lt;p&gt;And it turns out the the seed for this is controlled by the StringTools:-Randomize command.&lt;/p&gt;
&lt;p&gt;The following is done in the commandline interface of 64bit Maple 16.01 on Linux. The behavior seems similar in Maple 14.01 and 15.01.&lt;/p&gt;
&lt;pre&gt;&amp;gt; restart:          
&amp;gt; with(combinat):   
&amp;gt; L:=[1,2,3]:       
&amp;gt; randperm(L), randperm(L);

                             [2, 1, 3], [1, 3, 2]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; L:=[1,2,3]:              
&amp;gt; randperm(L), randperm(L);

                             [2, 1, 3], [1, 3, 2]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; StringTools:-Randomize():
&amp;gt; L:=[1,2,3]:
&amp;gt; randperm(L), randperm(L);

                             [1, 2, 3], [3, 2, 1]

&amp;gt; restart:                 
&amp;gt; with(combinat):          
&amp;gt; StringTools:-Randomize():
&amp;gt; L:=[1,2,3]:              
&amp;gt; randperm(L), randperm(L);

                             [3, 1, 2], [2, 1, 3]
&lt;/pre&gt;
&lt;p&gt;Of course, this might be better handled in a centralized location (ie. the `randomize` command, and/or RandomTools package).&lt;/p&gt;
&lt;!--break--&gt;
&lt;p&gt;Dave Linder&lt;br&gt; Mathematical Software, Maplesoft&lt;/p&gt;</description>
      <guid>140541</guid>
      <pubDate>Tue, 20 Nov 2012 00:58:47 Z</pubDate>
      <itunes:author>Dave L</itunes:author>
      <author>Dave L</author>
    </item>
    <item>
      <title>Thanks a lot. The proposed method seems to</title>
      <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always?ref=Feed:MaplePrimes:randperm in MapleTA produces always the same permutation:Comments#comment140467</link>
      <itunes:summary>&lt;p&gt;Thanks a lot. The proposed method seems to work with &lt;strong&gt;&lt;span class="mainBody document"&gt;RandomMatrix&lt;/span&gt;&lt;/strong&gt; but didn't work for me with &lt;strong&gt;randperm&lt;/strong&gt;. I now found a working but ineffective solution. I used&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $m=4;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $s=range(4,100);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pb=maple("with(combinat,randperm):[seq(randperm($m),i=1..$s)]");&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/pre&gt;
&lt;p&gt;though I only need 2 permutations and use $pb[$s] and $pb[$s-1] in the rest of the program.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Thanks a lot. The proposed method seems to work with &lt;strong&gt;&lt;span class="mainBody document"&gt;RandomMatrix&lt;/span&gt;&lt;/strong&gt; but didn't work for me with &lt;strong&gt;randperm&lt;/strong&gt;. I now found a working but ineffective solution. I used&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $m=4;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $s=range(4,100);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pb=maple("with(combinat,randperm):[seq(randperm($m),i=1..$s)]");&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :&lt;/pre&gt;
&lt;p&gt;though I only need 2 permutations and use $pb[$s] and $pb[$s-1] in the rest of the program.&lt;/p&gt;</description>
      <guid>140467</guid>
      <pubDate>Sat, 17 Nov 2012 03:05:09 Z</pubDate>
      <itunes:author>MichaelKaplan</itunes:author>
      <author>MichaelKaplan</author>
    </item>
    <item>
      <title>Oops, my mistake, wrong package.</title>
      <link>http://www.mapleprimes.com/questions/140400-Randperm-In-MapleTA-Produces-Always?ref=Feed:MaplePrimes:randperm in MapleTA produces always the same permutation:Comments#comment140470</link>
      <itunes:summary>&lt;p&gt;The combinat package does not use the same seed.&amp;nbsp; You can use the command&lt;/p&gt;
&lt;p&gt;&lt;img class="math" src="http://www.mapleprimes.com/MapleImage.ashx?f=04df27417af2d85463b846c1a101feff.gif" alt="Statistics:-Shuffle([seq(1..n)])"&gt; to get a permutation of the first n positive integers.&amp;nbsp; This would mean using code similar to the following:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $n=3;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $seed=range(1000,10000000);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pb=maple("RandomTools[SetState](state=$seed);&lt;br&gt;             [Statistics:-Shuffle([seq(1..$n)]),Statistics:-Shuffle([seq(1..$n)])");&lt;br&gt;&lt;br&gt;I hope that is better.&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;The combinat package does not use the same seed.&amp;nbsp; You can use the command&lt;/p&gt;
&lt;p&gt;&lt;img class="math" src="http://www.mapleprimes.com/MapleImage.ashx?f=04df27417af2d85463b846c1a101feff.gif" alt="Statistics:-Shuffle([seq(1..n)])"&gt; to get a permutation of the first n positive integers.&amp;nbsp; This would mean using code similar to the following:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; \code{&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $n=3;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $seed=range(1000,10000000);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pb=maple("RandomTools[SetState](state=$seed);&lt;br&gt;             [Statistics:-Shuffle([seq(1..$n)]),Statistics:-Shuffle([seq(1..$n)])");&lt;br&gt;&lt;br&gt;I hope that is better.&lt;/pre&gt;</description>
      <guid>140470</guid>
      <pubDate>Sat, 17 Nov 2012 05:24:38 Z</pubDate>
      <itunes:author>jaytreiman</itunes:author>
      <author>jaytreiman</author>
    </item>
  </channel>
</rss>