Rev 4158 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
!if $wims_read_parm!=slib_header
!goto proc
!endif
slib_title=Selective shuffle
slib_parms=3\
,n\
n,m\
n,k
slib_author=Gang Xiao
slib_out=the shuffled list (empty if error)
slib_comment=Selective shuffle: let 1<=m<=n and 1<=k<=n. Output a shuffled list\
of m non-repeating random integers within {1,2,...,n}, that always contains k.\
<p>n is limited to 100.
slib_example= 10,7,2
!exit
:proc
!distribute items $wims_read_parm into slib_n,slib_m,slib_k
!bound slib_n between integer 1 and 100 default 0
!bound slib_m between integer 1 and $slib_n default $slib_n
!bound slib_k between integer 1 and $slib_n default $slib_n
!if $slib_n=0
!reset slib_out
!exit
!endif
slib_sh=!shuffle $slib_n-1
slib_sh=!item 1 to $slib_m-1 of $slib_sh
slib_sh2=$slib_k
!for slib_i=1 to $slib_m-1
slib_l=!item $slib_i of $slib_sh
!if $slib_l>=$slib_k
!advance slib_l
!endif
slib_sh2=$slib_sh2,$slib_l
!next slib_i
slib_out=!shuffle $slib_sh2