1 /* random.cc
2 *
3 * Copyright (C) 2002 The gtkmm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <glibmm.h>
20
21 namespace Glib
22 {
23
Rand()24 Rand::Rand() : gobject_(g_rand_new())
25 {
26 }
27
Rand(guint32 seed)28 Rand::Rand(guint32 seed) : gobject_(g_rand_new_with_seed(seed))
29 {
30 }
31
~Rand()32 Rand::~Rand() noexcept
33 {
34 g_rand_free(gobject_);
35 }
36
37 void
set_seed(guint32 seed)38 Rand::set_seed(guint32 seed)
39 {
40 g_rand_set_seed(gobject_, seed);
41 }
42
43 bool
get_bool()44 Rand::get_bool()
45 {
46 return g_rand_boolean(gobject_);
47 }
48
49 guint32
get_int()50 Rand::get_int()
51 {
52 return g_rand_int(gobject_);
53 }
54
55 gint32
get_int_range(gint32 begin,gint32 end)56 Rand::get_int_range(gint32 begin, gint32 end)
57 {
58 return g_rand_int_range(gobject_, begin, end);
59 }
60
61 double
get_double()62 Rand::get_double()
63 {
64 return g_rand_double(gobject_);
65 }
66
67 double
get_double_range(double begin,double end)68 Rand::get_double_range(double begin, double end)
69 {
70 return g_rand_double_range(gobject_, begin, end);
71 }
72
73 } // namespace Glib
74