1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Generated by gir (https://github.com/gtk-rs/gir @ d7c0763cacbc)
// from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
// DO NOT EDIT

use crate::ffi;
use glib::translate::*;

glib::wrapper! {
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Random(Boxed<ffi::GeglRandom>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::gegl_random_get_type(), ptr as *mut _) as *mut ffi::GeglRandom,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::gegl_random_get_type(), ptr as *mut _),
        type_ => || ffi::gegl_random_get_type(),
    }
}

impl Random {
    /// Creates a new random number generator initialized with a random seed.
    /// This structure needs to be freed by the user with `gegl_random_free()`;
    #[doc(alias = "gegl_random_new")]
    pub fn new() -> Random {
        unsafe { from_glib_full(ffi::gegl_random_new()) }
    }

    /// Return an opaque structure associated to the seed.
    /// This structure needs to be freed by the user with `gegl_random_free()`;
    /// ## `seed`
    /// an integer seed, change for different permutation.
    #[doc(alias = "gegl_random_new_with_seed")]
    #[doc(alias = "new_with_seed")]
    pub fn with_seed(seed: u32) -> Random {
        unsafe { from_glib_full(ffi::gegl_random_new_with_seed(seed)) }
    }

    /// Return a new copy of an existing GeglRandom
    #[doc(alias = "gegl_random_duplicate")]
    #[must_use]
    pub fn duplicate(&mut self) -> Option<Random> {
        unsafe { from_glib_full(ffi::gegl_random_duplicate(self.to_glib_none_mut().0)) }
    }

    /// Return a random floating point number in range 0.0 .. 1.0.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `z`
    /// z coordinate (mipmap level)
    /// ## `n`
    /// number no (each x,y coordinate provides its own sequence of
    /// numbers
    #[doc(alias = "gegl_random_float")]
    pub fn float(&self, x: i32, y: i32, z: i32, n: i32) -> f32 {
        unsafe { ffi::gegl_random_float(self.to_glib_none().0, x, y, z, n) }
    }

    /// Return a random floating point number in the range specified,
    /// for the given x,y coordinates and GeglRandom provided, if multiple different
    /// numbers are needed pass in incrementing n's.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `z`
    /// z coordinate (mipmap level)
    /// ## `n`
    /// number no (each x,y coordinate provides its own sequence of
    /// numbers
    /// ## `min`
    /// minimum value
    /// ## `max`
    /// maximum value
    #[doc(alias = "gegl_random_float_range")]
    pub fn float_range(&self, x: i32, y: i32, z: i32, n: i32, min: f32, max: f32) -> f32 {
        unsafe { ffi::gegl_random_float_range(self.to_glib_none().0, x, y, z, n, min, max) }
    }

    /// Return a random integer number in range 0 .. MAX_UINT
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `z`
    /// z coordinate (mipmap level)
    /// ## `n`
    /// number no (each x,y coordinate provides its own sequence of
    /// numbers
    #[doc(alias = "gegl_random_int")]
    pub fn int(&self, x: i32, y: i32, z: i32, n: i32) -> u32 {
        unsafe { ffi::gegl_random_int(self.to_glib_none().0, x, y, z, n) }
    }

    /// Return a random integer point number in the range specified,
    /// for the given x,y coordinates and GeglRandom provided, if multiple different
    /// numbers are needed pass in incrementing n's.
    /// ## `x`
    /// x coordinate
    /// ## `y`
    /// y coordinate
    /// ## `z`
    /// z coordinate (mipmap level)
    /// ## `n`
    /// number no (each x,y coordinate provides its own sequence of
    /// numbers
    /// ## `min`
    /// minimum value
    /// ## `max`
    /// maximum value+1
    #[doc(alias = "gegl_random_int_range")]
    pub fn int_range(&self, x: i32, y: i32, z: i32, n: i32, min: i32, max: i32) -> i32 {
        unsafe { ffi::gegl_random_int_range(self.to_glib_none().0, x, y, z, n, min, max) }
    }

    /// Change the seed of an existing GeglRandom.
    /// ## `seed`
    /// an integer seed, change for different permutation.
    #[doc(alias = "gegl_random_set_seed")]
    pub fn set_seed(&mut self, seed: u32) {
        unsafe {
            ffi::gegl_random_set_seed(self.to_glib_none_mut().0, seed);
        }
    }
}

impl Default for Random {
    fn default() -> Self {
        Self::new()
    }
}