Ardour  9.0-pre0-386-g96ef4d20f2
pcg_rand.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef _pbd_pcg_rand_
20 #define _pbd_pcg_rand_
21 
22 #include <stdint.h>
23 #include "pbd/libpbd_visibility.h"
24 
25 namespace PBD
26 {
34 {
35 public:
36  PCGRand ();
37 
38  /* 32bit (0 .. 4294967295) */
39  uint32_t rand_u32 ();
40 
41  /* uniform integer min <= rand < max */
42  int rand (int max, int min = 0);
43 
44  /* unsigned float [0..1] */
45  float rand_uf ()
46  {
47  return rand_u32 () / 4294967295.f;
48  }
49 
50  /* signed float [-1..+1] */
51  float rand_sf ()
52  {
53  return (rand_u32 () / 2147483647.5f) - 1.f;
54  }
55 
56 private:
57  uint64_t _state;
58  uint64_t _inc;
59  int _foo;
60 };
61 
62 } // namespace PBD
63 
64 #endif
int rand(int max, int min=0)
float rand_sf()
Definition: pcg_rand.h:51
float rand_uf()
Definition: pcg_rand.h:45
uint64_t _inc
Definition: pcg_rand.h:58
uint64_t _state
Definition: pcg_rand.h:57
uint32_t rand_u32()
#define LIBPBD_API
Definition: axis_view.h:42