The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings Développement de WIMS
Summary Activity Forums Tracker Tasks Docs Surveys News SCM Files Listes Sympa

[#4456] shuffle

Date:
2008-09-07 10:15
Priority:
3
State:
Open
Submitted by:
Bernadette Perrin-Riou (bpr)
Assigned to:
Nobody (None)
Hardware:
none
Operating System:
none
Version:
none
Severity:
none
Resolution:
none
URL:
état:
Open
Summary:
shuffle

Detailed description
the command shuffle is bugged when there is only 1 item.
Certainly, when there is only 1 element, wims consider that
it is a number. But with the alea, it should be happened that
there is only one item (in word) in the list.

May test if the only element is a number or not ?

\text{a=shuffle(x)}
\text{b=shuffle(x,y)}
\text{c=shuffle(4)}
\statement{a=\a
b=\b
c = \c}

If it is dangerous to modify it in the code c, we may create un
slib shuffle.

Bernadette
Message  ↓
Date: 2008-12-31 11:47
Sender: Eric Reyssat

Sorry, my createxo program was unreadable.

Here it is, with X's to be replaced by backslashes.

%%%%%%%%%%%%%%%%%%%
Xtext{p=,x,}
Xtext{s=shuffle(Xp)}
Xinteger{n=items(Xp)}
Xinteger{ns=items(Xs)}
Xstatement{Xp // Xs // Xn // Xns}
%%%%%%%%%%%%%%%%%%%
Eric

Date: 2008-12-31 11:36
Sender: Eric Reyssat

What is the best wanted behaviour for shuffle ?

I tested the current behaviour with the following text in createxo

%%%%%%%%%%%%%%%%
ext{p=,x,}
ext{s=shuffle(p)}
integer{n=items(p)}
integer{ns=items(s)}
statement{p // s //
//
s}
%%%%%%%%%%%%%%%%



The result is :

p shuffle(p) items(p) items(shuffle(p))

6 4,3,5,2,6,1 1 6
3.14 3,1,2 1 3
10^6 462,1334,1127,1032,1637,... 1 2000 (limited by MAX_RANDPERM)
0 1 0
-6 1 0
"6" 1 0
x 1 0
x,y,z z,x,y 3 3
x,y, y,x 3 2
x,y,,, y,x,, 5 4
,x,y y,,x 3 3
6, 6 2 1
,6 6, 2 2
[x,y] 1 0
"x,y" y","x 2 2
x y , y x y x,x y 2 2


I propose to change only the cases where nothing is returned at present ; it will return p itself instead.

This would leave unchanged :
- the limitation to 2000 terms
- the fact that the last (only this one) term of the list is omitted if empty ; this permits to differentiate shuffle(4) from shuffle(4,) but implies a difference between number of items before and after shuffling.
- the strange (but logic) behaviour for p="x,y".

What about the danger ? shuffle is not used in the code.
It is used in some scripts. Examples :
public_html/scripts/oef/en/qcm/src/ordered.oef: ext{shuff=shuffle(datacnt)}
public_html/scripts/dialog/var.proc: nn=!itemcnt $shufflelist
public_html/scripts/deduc/meth2b.proc: s=!shuffle $n
...

and it is used in many models and exercices. I think (but not completely verified) that the current behaviour of returning nothing is never voluntarily used. So it seems preferable for simplicity to change the calc.c function shuffle than making a new library script

Any opinion ?

Eric

No related tasks

No attached documents

No changes have been made to this item