2
/* cs_randperm: random permutation. p=cs_randperm(n,0) is 1:n,
3
* p=cs_randperm(n,-1) is n:-1:1. p = cs_randperm (n,seed) is a random
4
* permutation using the given seed (where seed is not 0 or -1).
5
* seed defaults to 1. A single seed always gives a repeatable permutation.
6
* Use p = cs_randperm(n,rand) to get a permutation that varies with each use.
13
const mxArray *pargin [ ]
18
if (nargout > 1 || nargin < 1 || nargin > 2)
20
mexErrMsgTxt ("Usage: p = cs_randperm(n,seed)") ;
22
seed = (nargin > 1) ? mxGetScalar (pargin [1]) : 1 ;
23
iseed = (seed > 0 && seed < 1) ? (seed * RAND_MAX) : seed ;
24
n = mxGetScalar (pargin [0]) ;
26
p = cs_dl_randperm (n, iseed) ;
27
pargout [0] = cs_dl_mex_put_int (p, n, 1, 1) ; /* return p */