bzr branch
http://gegoxaren.bato24.eu/bzr/vqdr/trunk
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
1 |
/*
|
|
62
by Gustav Hartvigsson
various changes |
2 |
* The contests of this file is in the Public Domain.
|
|
19
by Gustav Hartvigsson
Added Round Up and Round Down function classes. |
3 |
*
|
4 |
* Created by Gustav Hartivgsson.
|
|
5 |
*/
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
6 |
|
7 |
namespace Vee { |
|
|
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 |
*/
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
14 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
15 |
public class Random { |
16 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
17 |
private static GLib.Once<Vee.Random> _instance; |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
18 |
|
19 |
private GLib.Rand rand; |
|
20 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
21 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
22 |
private Random () { |
23 |
this.rand = new GLib.Rand (); |
|
24 |
} |
|
25 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
26 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
27 |
public static Random get_instance () { |
|
58
by Gustav Hartvigsson
* Switch rand from static Randow instance, to static GLib.Once<Random>. This should be safer. |
28 |
return _instance.once (() => { |
29 |
return new Random (); |
|
30 |
}); |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
31 |
} |
32 |
|
|
33 |
/* **** Instance versions *** */ |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
34 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
35 |
public double get_double () { |
36 |
return rand.next_double (); |
|
37 |
} |
|
38 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
39 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
40 |
public double get_double_range (double begin, double end) { |
41 |
return rand.double_range (begin, end); |
|
42 |
} |
|
43 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
44 |
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
45 |
public int32 get_int () { |
46 |
return (int32) rand.next_int (); |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
47 |
} |
48 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
49 |
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
50 |
public int32 get_int_range (int32 begin, int32 end) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
51 |
return rand.int_range ((int32) begin, (int32) end); |
52 |
} |
|
53 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
54 |
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
55 |
public void seed (int32 seed) { |
|
62
by Gustav Hartvigsson
various changes |
56 |
rand.set_seed (seed.abs()); |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
57 |
} |
58 |
|
|
59 |
|
|
60 |
/* **** Static versions *** */ |
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
61 |
|
|
62
by Gustav Hartvigsson
various changes |
62 |
public static int32 get_static_int () { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
63 |
Random r = Random.get_instance (); |
64 |
return r.get_int (); |
|
65 |
} |
|
66 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
67 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
68 |
public static double get_static_double () { |
69 |
Random r = Random.get_instance (); |
|
70 |
return r.get_double (); |
|
71 |
} |
|
72 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
73 |
|
|
52.1.3
by Gustav Hartvigsson
int -> int32 |
74 |
public static int32 get_static_int_range (int32 begin, int32 end) { |
|
1
by Gustav Hartvigsson
* Initial code - far from done |
75 |
Random r = Random.get_instance (); |
76 |
return r.get_int_range (begin, end); |
|
77 |
} |
|
78 |
|
|
|
64
by Gustav Hartvigsson
[General] Major refactoring. Utils -> Vee nenaming. |
79 |
|
|
1
by Gustav Hartvigsson
* Initial code - far from done |
80 |
public static double get_static_double_range (double begin, double end) { |
81 |
Random r = Random.get_instance (); |
|
82 |
return r.get_double_range (begin, end); |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
|
|
87 |
}
|
|
88 |