Go to the documentation of this file.00001 #include "cs.h"
00002
00003
00004
00005 int *cs_randperm (int n, int seed)
00006 {
00007 int *p, k, j, t ;
00008 if (seed == 0) return (NULL) ;
00009 p = cs_malloc (n, sizeof (int)) ;
00010 if (!p) return (NULL) ;
00011 for (k = 0 ; k < n ; k++) p [k] = n-k-1 ;
00012 if (seed == -1) return (p) ;
00013 srand (seed) ;
00014 for (k = 0 ; k < n ; k++)
00015 {
00016 j = k + (rand ( ) % (n-k)) ;
00017 t = p [j] ;
00018 p [j] = p [k] ;
00019 p [k] = t ;
00020 }
00021 return (p) ;
00022 }