/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
19 by Gustav Hartvigsson
Added Round Up and Round Down function classes.
1
/*
2
 * The contects of this file is in the Public Domain.
3
 *
4
 * Created by Gustav Hartivgsson.
5
 */
54 by Gustav Hartvigsson
More work torwards inperementing the parser.
6
[CCode (cname = "V", cprefix = "v_")]
36 by Gustav Hartvigsson
Refactoring.
7
namespace Utils {
1 by Gustav Hartvigsson
* Initial code - far from done
8
  
9
  /**
10
   * At the moment this just wraps the GLib Rand things.
11
   * 
12
   * This also provides a static version of the methods.
13
   */
54 by Gustav Hartvigsson
More work torwards inperementing the parser.
14
  [CCode (cname = "VRandom", cprefix = "v_random_")]
1 by Gustav Hartvigsson
* Initial code - far from done
15
  public class Random {
16
    
17
    private static Random? _instance = null;
18
    
19
    private GLib.Rand rand;
20
    
21
    private Random () {
22
      this.rand = new GLib.Rand ();
23
    }
24
    
25
    public static Random get_instance () {
26
      if (_instance == null) {
27
       _instance = new Random ();
28
      }
29
      return _instance;
30
    }
31
    
32
    /* **** Instance versions *** */
33
    public double get_double () {
34
      return rand.next_double ();
35
    }
36
    
37
    public double get_double_range (double begin, double end) {
38
      return rand.double_range (begin, end);
39
    }
40
    
52.1.3 by Gustav Hartvigsson
int -> int32
41
    public int32 get_int () {
42
      return (int32) rand.next_int ();
1 by Gustav Hartvigsson
* Initial code - far from done
43
    }
44
    
52.1.3 by Gustav Hartvigsson
int -> int32
45
    public int32 get_int_range (int32 begin, int32 end) {
1 by Gustav Hartvigsson
* Initial code - far from done
46
      return rand.int_range ((int32) begin, (int32) end);
47
    }
48
    
52.1.3 by Gustav Hartvigsson
int -> int32
49
    public void seed (int32 seed) {
1 by Gustav Hartvigsson
* Initial code - far from done
50
      rand.set_seed ((uint32) seed);
51
    }
52
    
53
    
54
    /* **** Static versions *** */
52.1.3 by Gustav Hartvigsson
int -> int32
55
      public static int32 get_static_int () {
1 by Gustav Hartvigsson
* Initial code - far from done
56
      Random r = Random.get_instance ();
57
      return r.get_int ();
58
    }
59
    
60
    public static double get_static_double () {
61
      Random r = Random.get_instance ();
62
      return r.get_double ();
63
    }
64
    
52.1.3 by Gustav Hartvigsson
int -> int32
65
    public static int32 get_static_int_range (int32 begin, int32 end) {
1 by Gustav Hartvigsson
* Initial code - far from done
66
      Random r = Random.get_instance ();
67
      return r.get_int_range (begin, end);
68
    }
69
    
70
    public static double get_static_double_range (double begin, double end) {
71
      Random r = Random.get_instance ();
72
      return r.get_double_range (begin, end);
73
    }
74
    
75
  }
76
  
77
}
78