/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace VQDR.Common {
  
  /**
   * At the moment this just wraps the GLib Rand things.
   * 
   * This also provides a static version of the methods.
   */
  public class Random {
    
    private static Random? _instance = null;
    
    private GLib.Rand rand;
    
    private Random () {
      this.rand = new GLib.Rand ();
    }
    
    public static Random get_instance () {
      if (_instance == null) {
       _instance = new Random ();
      }
      return _instance;
    }
    
    /* **** Instance versions *** */
    public double get_double () {
      return rand.next_double ();
    }
    
    public double get_double_range (double begin, double end) {
      return rand.double_range (begin, end);
    }
    
    public int get_int () {
      return (int) rand.next_int ();
    }
    
    public int get_int_range (int begin, int end) {
      return rand.int_range ((int32) begin, (int32) end);
    }
    
    public void seed (int seed) {
      rand.set_seed ((uint32) seed);
    }
    
    
    /* **** Static versions *** */
    public static int get_static_int () {
      Random r = Random.get_instance ();
      return r.get_int ();
    }
    
    public static double get_static_double () {
      Random r = Random.get_instance ();
      return r.get_double ();
    }
    
    public static int get_static_int_range (int begin, int end) {
      Random r = Random.get_instance ();
      return r.get_int_range (begin, end);
    }
    
    public static double get_static_double_range (double begin, double end) {
      Random r = Random.get_instance ();
      return r.get_double_range (begin, end);
    }
    
  }
  
}