Subversion Repositories gelsvn

Rev

Rev 417 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
595 jab 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
 
417 jrf 7
#include "CGLA.h"
8
 
9
namespace
10
{
11
  unsigned int seed = 1;
12
  unsigned int current_rand = 1;
13
}
14
 
15
namespace CGLA
16
{
17
  void gel_srand(unsigned int s)
18
  {
19
    seed = current_rand = s;
20
  }
21
 
22
  unsigned int gel_rand(unsigned int k)
23
  {
24
    unsigned int b = 3125;
25
    unsigned int c = 49;
26
    unsigned int result = seed;
27
 
28
    for (;k > 0;k>>=1)
29
    {
30
      if (k & 1) result = result * b + c;
31
      c += b * c;
32
      b *= b;
33
    }
34
    return result;
35
  }
36
 
37
  unsigned int gel_rand()
38
  {
595 jab 39
    const unsigned int b = 3125;
40
    const unsigned int c = 49;
417 jrf 41
 
42
    current_rand = current_rand*b + c;
43
    return current_rand;
44
  }
45
}