/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: 2022-06-01 12:44:04 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220601124404-mpv4761nr16f0duq
run_gdb.sh +x

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
namespace VQDR.Common {
 
1
/*
 
2
 * The contects of this file is in the Public Domain.
 
3
 *
 
4
 * Created by Gustav Hartivgsson.
 
5
 */
 
6
[CCode (cname = "V", cprefix = "v_")]
 
7
namespace Utils {
2
8
  
3
9
  /**
4
10
   * At the moment this just wraps the GLib Rand things.
5
11
   * 
6
12
   * This also provides a static version of the methods.
7
13
   */
 
14
  [CCode (cname = "VRandom", cprefix = "v_random_")]
8
15
  public class Random {
9
16
    
10
17
    private static Random? _instance = null;
31
38
      return rand.double_range (begin, end);
32
39
    }
33
40
    
34
 
    public int get_int () {
35
 
      return (int) rand.next_int ();
 
41
    public int32 get_int () {
 
42
      return (int32) rand.next_int ();
36
43
    }
37
44
    
38
 
    public int get_int_range (int begin, int end) {
 
45
    public int32 get_int_range (int32 begin, int32 end) {
39
46
      return rand.int_range ((int32) begin, (int32) end);
40
47
    }
41
48
    
42
 
    public void seed (int seed) {
 
49
    public void seed (int32 seed) {
43
50
      rand.set_seed ((uint32) seed);
44
51
    }
45
52
    
46
53
    
47
54
    /* **** Static versions *** */
48
 
    public static int get_static_int () {
 
55
      public static int32 get_static_int () {
49
56
      Random r = Random.get_instance ();
50
57
      return r.get_int ();
51
58
    }
55
62
      return r.get_double ();
56
63
    }
57
64
    
58
 
    public static int get_static_int_range (int begin, int end) {
 
65
    public static int32 get_static_int_range (int32 begin, int32 end) {
59
66
      Random r = Random.get_instance ();
60
67
      return r.get_int_range (begin, end);
61
68
    }