"Fossies" - the Fresh Open Source Software Archive

Member "sip-0.12.1/macros/sip_randperm.sci" (18 Apr 2012, 1408 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scilab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 // This file was adapted from Octave.
    2 //
    3 // Original source code is Copyright (C) 1998 John W. Eaton
    4 //
    5 //
    6 // Octave is free software; you can redistribute it and/or modify it
    7 // under the terms of the GNU General Public License as published by
    8 // the Free Software Foundation; either version 2, or (at your option)
    9 // any later version.
   10 //
   11 // Octave is distributed in the hope that it will be useful, but
   12 // WITHOUT ANY WARRANTY; without even the implied warranty of
   13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14 // General Public License for more details.
   15 //
   16 // You should have received a copy of the GNU General Public License
   17 // along with Octave; see the file COPYING.  If not, write to the Free
   18 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   19 // 02110-1301, USA.
   20 
   21 // -*- texinfo -*-
   22 // @deftypefn {Function File} {} randperm (@var{n})
   23 // Return a row vector containing a random permutation of the
   24 // integers from 1 to @var{n}.
   25 // @end deftypefn
   26 
   27 // Author: "James R. Van Zandt" <jrv@vanzandt.mv.com>
   28 // Adapted-By: jwe
   29 
   30 function retval = sip_randperm(n)
   31 
   32 [nargout, nargin] = argn();
   33 
   34 if ((nargin == 1) & ((type(n)==1) & (size(n,1)==1) & (size(n,2)==1)) & (floor (n) == n)) then
   35   if (n >= 0) then
   36     [junk, retval] = gsort(rand (1, n));
   37   else
   38     error ("randperm: argument must be non-negative");
   39   end
   40 else
   41   error("randperm (n)");
   42 end
   43 endfunction