~ubuntu-branches/ubuntu/oneiric/suitesparse/oneiric

« back to all changes in this revision

Viewing changes to CXSparse/Source/cs_randperm.c

  • Committer: Bazaar Package Importer
  • Author(s): Nick Ellery
  • Date: 2009-06-14 19:15:52 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090614191552-2hliya5q8n1quseu
Tags: 1:3.4.0-1ubuntu1
* Merge from debian unstable, remaining changes (LP: #387137):
  - debian/control:
    - demote libatlas-doc from recommends to suggests as it is not in main
    - drop recommends on doc-central as it is not in main

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
CS_INT *cs_randperm (CS_INT n, CS_INT seed)
6
6
{
7
7
    CS_INT *p, k, j, t ;
8
 
    if (seed == 0) return (NULL) ;      /* return p = NULL (identity) */
9
 
    p = cs_malloc (n, sizeof (CS_INT)) ;        /* allocate result */
10
 
    if (!p) return (NULL) ;             /* out of memory */
 
8
    if (seed == 0) return (NULL) ;      /* return p = NULL (identity) */
 
9
    p = cs_malloc (n, sizeof (CS_INT)) ;   /* allocate result */
 
10
    if (!p) return (NULL) ;             /* out of memory */
11
11
    for (k = 0 ; k < n ; k++) p [k] = n-k-1 ;
12
 
    if (seed == -1) return (p) ;        /* return reverse permutation */
13
 
    srand (seed) ;                      /* get new random number seed */
 
12
    if (seed == -1) return (p) ;        /* return reverse permutation */
 
13
    srand (seed) ;                      /* get new random number seed */
14
14
    for (k = 0 ; k < n ; k++)
15
15
    {
16
 
        j = k + (rand ( ) % (n-k)) ;    /* j = rand CS_INT in range k to n-1 */
17
 
        t = p [j] ;                     /* swap p[k] and p[j] */
18
 
        p [j] = p [k] ;
19
 
        p [k] = t ;
 
16
        j = k + (rand ( ) % (n-k)) ;    /* j = rand CS_INT in range k to n-1 */
 
17
        t = p [j] ;                     /* swap p[k] and p[j] */
 
18
        p [j] = p [k] ;
 
19
        p [k] = t ;
20
20
    }
21
21
    return (p) ;
22
22
}