numbas/Numbas — Issue #142: creating permutations
Author: BillFoster
Created: 2012-02-24 15:35:27+00:00
State: open

I need permutations of [0,1,..,n-1]

So I tried to use the function, deal in math.js. First I had to include it in jme.js, along with randomint

new funcObj('randomint', [TNum], TNum, math.randomint);
new funcObj('deal', [TNum] , TList , math.deal);

randomint works but not deal

I then rewrote it as

//returns a random number in range [0..N-1]
randomint: function(N) {
return Math.floor(N*(Math.random()%1));
},

//a random shuffling of the numbers [0..N-1]
deal: function(N)
{
var J, K, Q = new Array(N);
for(var i=0;i