Subversion Repositories gelsvn

Rev

Rev 417 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 417 Rev 595
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
1
#include "CGLA.h"
7
#include "CGLA.h"
2
 
8
 
3
namespace
9
namespace
4
{
10
{
5
  unsigned int seed = 1;
11
  unsigned int seed = 1;
6
  unsigned int current_rand = 1;
12
  unsigned int current_rand = 1;
7
}
13
}
8
 
14
 
9
namespace CGLA
15
namespace CGLA
10
{
16
{
11
  void gel_srand(unsigned int s)
17
  void gel_srand(unsigned int s)
12
  {
18
  {
13
    seed = current_rand = s;
19
    seed = current_rand = s;
14
  }
20
  }
15
 
21
 
16
  unsigned int gel_rand(unsigned int k)
22
  unsigned int gel_rand(unsigned int k)
17
  {
23
  {
18
    unsigned int b = 3125;
24
    unsigned int b = 3125;
19
    unsigned int c = 49;
25
    unsigned int c = 49;
20
    unsigned int result = seed;
26
    unsigned int result = seed;
21
 
27
 
22
    for (;k > 0;k>>=1)
28
    for (;k > 0;k>>=1)
23
    {
29
    {
24
      if (k & 1) result = result * b + c;
30
      if (k & 1) result = result * b + c;
25
      c += b * c;
31
      c += b * c;
26
      b *= b;
32
      b *= b;
27
    }
33
    }
28
    return result;
34
    return result;
29
  }
35
  }
30
 
36
 
31
  unsigned int gel_rand()
37
  unsigned int gel_rand()
32
  {
38
  {
33
    unsigned int b = 3125;
39
    const unsigned int b = 3125;
34
    unsigned int c = 49;
40
    const unsigned int c = 49;
35
 
41
 
36
    current_rand = current_rand*b + c;
42
    current_rand = current_rand*b + c;
37
    return current_rand;
43
    return current_rand;
38
  }
44
  }
39
}
45
}
40
 
46
 
41

Generated by GNU Enscript 1.6.6.
47

Generated by GNU Enscript 1.6.6.
42
 
48
 
43
 
49
 
44
 
50