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
{
33
class
LIBPBD_API
PCGRand
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
PBD::PCGRand
Definition:
pcg_rand.h:34
PBD::PCGRand::rand
int rand(int max, int min=0)
PBD::PCGRand::rand_sf
float rand_sf()
Definition:
pcg_rand.h:51
PBD::PCGRand::rand_uf
float rand_uf()
Definition:
pcg_rand.h:45
PBD::PCGRand::_inc
uint64_t _inc
Definition:
pcg_rand.h:58
PBD::PCGRand::_foo
int _foo
Definition:
pcg_rand.h:59
PBD::PCGRand::_state
uint64_t _state
Definition:
pcg_rand.h:57
PBD::PCGRand::PCGRand
PCGRand()
PBD::PCGRand::rand_u32
uint32_t rand_u32()
libpbd_visibility.h
LIBPBD_API
#define LIBPBD_API
Definition:
libpbd_visibility.h:50
PBD
Definition:
axis_view.h:42
libs
pbd
pbd
pcg_rand.h
Generated on Sun Nov 10 2024 05:34:29 for Ardour by
1.9.1