1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// The GRand struct is an opaque data structure. It should only be
15// accessed through the g_rand_* functions.
16type Rand struct {
17 _ structs.HostLayout
18}
19
20var xRandGLibType func() types.GType
21
22func RandGLibType() types.GType {
23 return xRandGLibType()
24}
25
26func (x *Rand) GoPointer() uintptr {
27 return uintptr(unsafe.Pointer(x))
28}
29
30var xNewRand func() *Rand
31
32// Creates a new random number generator initialized with a seed taken
33// either from `/dev/urandom` (if existing) or from the current time
34// (as a fallback).
35//
36// On Windows, the seed is taken from rand_s().
37func NewRand() *Rand {
38
39 cret := xNewRand()
40 return cret
41}
42
43var xNewRandWithSeed func(uint32) *Rand
44
45// Creates a new random number generator initialized with @seed.
46func NewRandWithSeed(SeedVar uint32) *Rand {
47
48 cret := xNewRandWithSeed(SeedVar)
49 return cret
50}
51
52var xNewRandWithSeedArray func(uint32, uint) *Rand
53
54// Creates a new random number generator initialized with @seed.
55func NewRandWithSeedArray(SeedVar uint32, SeedLengthVar uint) *Rand {
56
57 cret := xNewRandWithSeedArray(SeedVar, SeedLengthVar)
58 return cret
59}
60
61var xRandCopy func(uintptr) *Rand
62
63// Copies a #GRand into a new one with the same exact state as before.
64// This way you can take a snapshot of the random number generator for
65// replaying later.
66func (x *Rand) Copy() *Rand {
67
68 cret := xRandCopy(x.GoPointer())
69 return cret
70}
71
72var xRandDouble func(uintptr) float64
73
74// Returns the next random #gdouble from @rand_ equally distributed over
75// the range [0..1).
76func (x *Rand) Double() float64 {
77
78 cret := xRandDouble(x.GoPointer())
79 return cret
80}
81
82var xRandDoubleRange func(uintptr, float64, float64) float64
83
84// Returns the next random #gdouble from @rand_ equally distributed over
85// the range [@begin..@end).
86func (x *Rand) DoubleRange(BeginVar float64, EndVar float64) float64 {
87
88 cret := xRandDoubleRange(x.GoPointer(), BeginVar, EndVar)
89 return cret
90}
91
92var xRandFree func(uintptr)
93
94// Frees the memory allocated for the #GRand.
95func (x *Rand) Free() {
96
97 xRandFree(x.GoPointer())
98
99}
100
101var xRandInt func(uintptr) uint32
102
103// Returns the next random #guint32 from @rand_ equally distributed over
104// the range [0..2^32-1].
105func (x *Rand) Int() uint32 {
106
107 cret := xRandInt(x.GoPointer())
108 return cret
109}
110
111var xRandIntRange func(uintptr, int32, int32) int32
112
113// Returns the next random #gint32 from @rand_ equally distributed over
114// the range [@begin..@end-1].
115func (x *Rand) IntRange(BeginVar int32, EndVar int32) int32 {
116
117 cret := xRandIntRange(x.GoPointer(), BeginVar, EndVar)
118 return cret
119}
120
121var xRandSetSeed func(uintptr, uint32)
122
123// Sets the seed for the random number generator #GRand to @seed.
124func (x *Rand) SetSeed(SeedVar uint32) {
125
126 xRandSetSeed(x.GoPointer(), SeedVar)
127
128}
129
130var xRandSetSeedArray func(uintptr, uint32, uint)
131
132// Initializes the random number generator by an array of longs.
133// Array can be of arbitrary size, though only the first 624 values
134// are taken. This function is useful if you have many low entropy
135// seeds, or if you require more then 32 bits of actual entropy for
136// your application.
137func (x *Rand) SetSeedArray(SeedVar uint32, SeedLengthVar uint) {
138
139 xRandSetSeedArray(x.GoPointer(), SeedVar, SeedLengthVar)
140
141}
142
143var xRandomDouble func() float64
144
145// Returns a random #gdouble equally distributed over the range [0..1).
146func RandomDouble() float64 {
147
148 cret := xRandomDouble()
149
150 return cret
151}
152
153var xRandomDoubleRange func(float64, float64) float64
154
155// Returns a random #gdouble equally distributed over the range
156// [@begin..@end).
157func RandomDoubleRange(BeginVar float64, EndVar float64) float64 {
158
159 cret := xRandomDoubleRange(BeginVar, EndVar)
160
161 return cret
162}
163
164var xRandomInt func() uint32
165
166// Return a random #guint32 equally distributed over the range
167// [0..2^32-1].
168func RandomInt() uint32 {
169
170 cret := xRandomInt()
171
172 return cret
173}
174
175var xRandomIntRange func(int32, int32) int32
176
177// Returns a random #gint32 equally distributed over the range
178// [@begin..@end-1].
179func RandomIntRange(BeginVar int32, EndVar int32) int32 {
180
181 cret := xRandomIntRange(BeginVar, EndVar)
182
183 return cret
184}
185
186var xRandomSetSeed func(uint32)
187
188// Sets the seed for the global random number generator, which is used
189// by the g_random_* functions, to @seed.
190func RandomSetSeed(SeedVar uint32) {
191
192 xRandomSetSeed(SeedVar)
193
194}
195
196func init() {
197 core.SetPackageName("GLIB", "glib-2.0")
198 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
199 var libs []uintptr
200 for _, libPath := range core.GetPaths("GLIB") {
201 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
202 if err != nil {
203 panic(err)
204 }
205 libs = append(libs, lib)
206 }
207
208 core.PuregoSafeRegister(&xRandomDouble, libs, "g_random_double")
209 core.PuregoSafeRegister(&xRandomDoubleRange, libs, "g_random_double_range")
210 core.PuregoSafeRegister(&xRandomInt, libs, "g_random_int")
211 core.PuregoSafeRegister(&xRandomIntRange, libs, "g_random_int_range")
212 core.PuregoSafeRegister(&xRandomSetSeed, libs, "g_random_set_seed")
213
214 core.PuregoSafeRegister(&xRandGLibType, libs, "g_rand_get_type")
215
216 core.PuregoSafeRegister(&xNewRand, libs, "g_rand_new")
217 core.PuregoSafeRegister(&xNewRandWithSeed, libs, "g_rand_new_with_seed")
218 core.PuregoSafeRegister(&xNewRandWithSeedArray, libs, "g_rand_new_with_seed_array")
219
220 core.PuregoSafeRegister(&xRandCopy, libs, "g_rand_copy")
221 core.PuregoSafeRegister(&xRandDouble, libs, "g_rand_double")
222 core.PuregoSafeRegister(&xRandDoubleRange, libs, "g_rand_double_range")
223 core.PuregoSafeRegister(&xRandFree, libs, "g_rand_free")
224 core.PuregoSafeRegister(&xRandInt, libs, "g_rand_int")
225 core.PuregoSafeRegister(&xRandIntRange, libs, "g_rand_int_range")
226 core.PuregoSafeRegister(&xRandSetSeed, libs, "g_rand_set_seed")
227 core.PuregoSafeRegister(&xRandSetSeedArray, libs, "g_rand_set_seed_array")
228
229}