1
namespace VQDR.Common {
4
* At the moment this just wraps the GLib Rand things.
6
* This also provides a static version of the methods.
10
private static Random? _instance = null;
12
private GLib.Rand rand;
15
this.rand = new GLib.Rand ();
18
public static Random get_instance () {
19
if (_instance == null) {
20
_instance = new Random ();
25
/* **** Instance versions *** */
26
public double get_double () {
27
return rand.next_double ();
30
public double get_double_range (double begin, double end) {
31
return rand.double_range (begin, end);
34
public int get_int () {
35
return (int) rand.next_int ();
38
public int get_int_range (int begin, int end) {
39
return rand.int_range ((int32) begin, (int32) end);
42
public void seed (int seed) {
43
rand.set_seed ((uint32) seed);
47
/* **** Static versions *** */
48
public static int get_static_int () {
49
Random r = Random.get_instance ();
53
public static double get_static_double () {
54
Random r = Random.get_instance ();
55
return r.get_double ();
58
public static int get_static_int_range (int begin, int end) {
59
Random r = Random.get_instance ();
60
return r.get_int_range (begin, end);
63
public static double get_static_double_range (double begin, double end) {
64
Random r = Random.get_instance ();
65
return r.get_double_range (begin, end);