/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/utils/random.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-21 22:39:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241221223917-jbt2ylyz9nxjss49
various changes
[utils/utils.vala]
* Removed uneeded int32_abs function

[utils/stack]
* more informative error when trying to pop an empty stack.

[utils/random.vala]
* added c_names to functions (probobly not needed).

[utils/pair.vala]
* Made compact
* made FreeFunc delegates unowned to fix error
* added constructor Pair.with_free_func ().

[utils/named_vector.vala]
* made class compact.

[utils/meson.build]
* Reordered files in list
* added logger.vala.

[utils/logger.vala]
* Added fast and easy logger class.

[utils/fast_number.vala]
* added a bunch of cname CCode attributes.

[general]
* Spelling in comments and functions.

[meson.build]
* Made dependancies easier to read
* added vala posix dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * The contects of this file is in the Public Domain.
 
2
 * The contests of this file is in the Public Domain.
3
3
 *
4
4
 * Created by Gustav Hartivgsson.
5
5
 */
18
18
    
19
19
    private GLib.Rand rand;
20
20
    
 
21
    [CCode (cname = "v_random_new")]
21
22
    private Random () {
22
23
      this.rand = new GLib.Rand ();
23
24
    }
24
25
    
 
26
    [CCode (cname = "v_random_get_instance")]
25
27
    public static Random get_instance () {
26
28
      return _instance.once (() => {
27
29
        return new Random ();
29
31
    }
30
32
    
31
33
    /* **** Instance versions *** */
 
34
    [CCode (cname = "v_random_get_double")]
32
35
    public double get_double () {
33
36
      return rand.next_double ();
34
37
    }
35
38
    
 
39
    [CCode (cname = "v_random_get_range")]
36
40
    public double get_double_range (double begin, double end) {
37
41
      return rand.double_range (begin, end);
38
42
    }
39
43
    
 
44
    [CCode (cname = "v_random_get_int")]
40
45
    public int32 get_int () {
41
46
      return (int32) rand.next_int ();
42
47
    }
43
48
    
 
49
    [CCode (cname = "v_random_get_int_range")]
44
50
    public int32 get_int_range (int32 begin, int32 end) {
45
51
      return rand.int_range ((int32) begin, (int32) end);
46
52
    }
47
53
    
 
54
    [CCode (cname = "v_random_seed")]
48
55
    public void seed (int32 seed) {
49
 
      rand.set_seed ((uint32) seed);
 
56
      rand.set_seed (seed.abs());
50
57
    }
51
58
    
52
59
    
53
60
    /* **** Static versions *** */
54
 
      public static int32 get_static_int () {
 
61
    [CCode (cname = "v_random_get_static_int")]
 
62
    public static int32 get_static_int () {
55
63
      Random r = Random.get_instance ();
56
64
      return r.get_int ();
57
65
    }
58
66
    
 
67
    [CCode (cname = "v_random_get_static_double")]
59
68
    public static double get_static_double () {
60
69
      Random r = Random.get_instance ();
61
70
      return r.get_double ();
62
71
    }
63
72
    
 
73
    [CCode (cname = "v_random_get_static_int_range")]
64
74
    public static int32 get_static_int_range (int32 begin, int32 end) {
65
75
      Random r = Random.get_instance ();
66
76
      return r.get_int_range (begin, end);
67
77
    }
68
78
    
 
79
    [CCode (cname = "v_random_get_static_double_range")]
69
80
    public static double get_static_double_range (double begin, double end) {
70
81
      Random r = Random.get_instance ();
71
82
      return r.get_double_range (begin, end);