libvisual  0.5.0
lv_random.h
1 /* Libvisual - The audio visualisation framework.
2  *
3  * Copyright (C) 2012 Libvisual team
4  * 2004-2006 Dennis Smit
5  *
6  * Authors: Chong Kai Xiong <kaixiong@codeleft.sg>
7  * Dennis Smit <ds@nerds-incorporated.org>
8  * Vitaly V. Bursov <vitalyvb@ukr.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as
12  * published by the Free Software Foundation; either version 2.1
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #ifndef _LV_RANDOM_H
26 #define _LV_RANDOM_H
27 
28 #include <libvisual/lvconfig.h>
29 #include <libvisual/lv_types.h>
30 #include <libvisual/lv_defines.h>
31 
37 #ifdef __cplusplus
38 
39 #include <memory>
40 
41 namespace LV {
42 
43  typedef uint32_t RandomSeed;
44 
48  class LV_API RandomContext
49  {
50  public:
51 
52  typedef RandomSeed Seed;
53 
59  explicit RandomContext (Seed seed);
60 
61  RandomContext (RandomContext const&) = delete;
62 
67 
71  ~RandomContext ();
72 
73  RandomContext& operator= (RandomContext const&) = delete;
74 
75  /*
76  * Move assignment operator
77  */
78  RandomContext& operator= (RandomContext&& rhs);
79 
85  void set_seed (uint32_t seed);
86 
92  uint32_t get_int ();
93 
102  uint32_t get_int (unsigned int min, unsigned int max);
103 
109  double get_double ();
110 
116  float get_float ();
117 
118  private:
119 
120  class Impl;
121  std::unique_ptr<Impl> m_impl;
122  };
123 
124 } // LV namespace
125 
126 #endif /* __cplusplus */
127 
128 /* LV C API */
129 
130 #ifdef __cplusplus
131 typedef ::LV::RandomContext VisRandomContext;
132 typedef ::LV::RandomSeed VisRandomSeed;
133 #else
134  typedef struct _VisRandomContext VisRandomContext;
135  struct _VisRandomContext;
136 
137  typedef uint32_t VisRandomSeed;
138 #endif
139 
140 LV_BEGIN_DECLS
141 
142 LV_API VisRandomContext *visual_random_context_new (VisRandomSeed seed);
143 LV_API void visual_random_context_free (VisRandomContext *rcontext);
144 
145 LV_API void visual_random_context_set_seed (VisRandomContext *rcontext, VisRandomSeed seed);
146 LV_API uint32_t visual_random_context_int (VisRandomContext *rcontext);
147 LV_API uint32_t visual_random_context_int_range (VisRandomContext *rcontext, unsigned int min, unsigned int max);
148 LV_API double visual_random_context_double (VisRandomContext *rcontext);
149 LV_API float visual_random_context_float (VisRandomContext *rcontext);
150 
151 LV_END_DECLS
152 
157 #endif /* _LV_RANDOM_H */