/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
 */
1 by Gustav Hartvigsson
* Initial code - far from done
6
namespace VQDR.Common {
7
  
8
  /**
9
   * At the moment this just wraps the GLib Rand things.
10
   * 
11
   * This also provides a static version of the methods.
12
   */
13
  public class Random {
14
    
15
    private static Random? _instance = null;
16
    
17
    private GLib.Rand rand;
18
    
19
    private Random () {
20
      this.rand = new GLib.Rand ();
21
    }
22
    
23
    public static Random get_instance () {
24
      if (_instance == null) {
25
       _instance = new Random ();
26
      }
27
      return _instance;
28
    }
29
    
30
    /* **** Instance versions *** */
31
    public double get_double () {
32
      return rand.next_double ();
33
    }
34
    
35
    public double get_double_range (double begin, double end) {
36
      return rand.double_range (begin, end);
37
    }
38
    
39
    public int get_int () {
40
      return (int) rand.next_int ();
41
    }
42
    
43
    public int get_int_range (int begin, int end) {
44
      return rand.int_range ((int32) begin, (int32) end);
45
    }
46
    
47
    public void seed (int seed) {
48
      rand.set_seed ((uint32) seed);
49
    }
50
    
51
    
52
    /* **** Static versions *** */
53
    public static int get_static_int () {
54
      Random r = Random.get_instance ();
55
      return r.get_int ();
56
    }
57
    
58
    public static double get_static_double () {
59
      Random r = Random.get_instance ();
60
      return r.get_double ();
61
    }
62
    
63
    public static int get_static_int_range (int begin, int end) {
64
      Random r = Random.get_instance ();
65
      return r.get_int_range (begin, end);
66
    }
67
    
68
    public static double get_static_double_range (double begin, double end) {
69
      Random r = Random.get_instance ();
70
      return r.get_double_range (begin, end);
71
    }
72
    
73
  }
74
  
75
}
76