Feature Selection Toolbox
FST4
UTIA · Czech Academy of Sciences
Home
Introduction
Usage
FST4 CLI
Demos
API Reference
Download
History
References
Legacy
FAQ
Contacts
Toggle main menu visibility
Loading...
Searching...
No Matches
_src_global
fst_rand.hpp
Go to the documentation of this file.
1
#ifndef FSTFSTRAND_H
2
#define FSTFSTRAND_H
3
/*
28
=========================================================================
29
Copyright and license:
30
* FST4 software (with the exception of any bundled or externally linked
31
third-party components) is Copyright (C) 2000-present Institute of
32
Information Theory and Automation of the Czech Academy of Sciences (UTIA).
33
* FST4 is free software: you can redistribute it and/or modify it under
34
the terms of the GNU Affero General Public License as published by the
35
Free Software Foundation, version 3. The full text of the license is in
36
the file LICENSE in the distribution root and at
37
https://www.gnu.org/licenses/agpl-3.0.html.
38
* FST4 is distributed in the hope that it will be useful, but WITHOUT ANY
39
WARRANTY; without even the implied warranty of MERCHANTABILITY or
40
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
41
License for more details.
42
* Closed-source use without the AGPL's copyleft obligations requires a
43
commercial license from UTIA; in case of interest write to
44
utia@utia.cas.cz. LICENSING.md in the distribution root explains both
45
options, the contributor license agreement that every contribution
46
requires, and the contacts (technical questions and pull requests:
47
somol@utia.cas.cz, with "FST" in the subject line).
48
========================================================================== */
49
50
namespace
FST
{
51
85
87
inline
unsigned
int
&
_fst_rand_state
() {
static
thread_local
unsigned
int
s = 1;
return
s; }
88
90
inline
void
fst_srand
(
unsigned
int
seed) {
_fst_rand_state
() = seed; }
91
93
inline
int
fst_rand
()
94
{
95
unsigned
int
& s =
_fst_rand_state
();
96
s = s * 214013u + 2531011u;
97
return
(
int
)((s >> 16) & 0x7fff);
98
}
99
101
const
int
FST_RAND_MAX
= 32767;
102
112
inline
unsigned
long
fst_rand_below
(
const
unsigned
long
n)
113
{
114
if
(n<=32768UL)
return
(
unsigned
long
)
fst_rand
()%n;
115
const
unsigned
long
r=((
unsigned
long)
fst_rand
()<<15)|(
unsigned
long
)
fst_rand
();
116
return
r%n;
117
}
118
119
}
// namespace FST
120
121
#endif
// FSTFSTRAND_H
FST
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition
data_accessor.hpp:80
FST::fst_srand
void fst_srand(unsigned int seed)
Seeds the calling thread's FST4 PRNG; use instead of std::srand().
Definition
fst_rand.hpp:90
FST::fst_rand
int fst_rand()
Returns the next pseudo-random draw in 0..FST_RAND_MAX; use instead of std::rand().
Definition
fst_rand.hpp:93
FST::fst_rand_below
unsigned long fst_rand_below(const unsigned long n)
Returns a pseudo-random index in 0..n-1 (n >= 1); use instead of fst_rand()n.
Definition
fst_rand.hpp:112
FST::FST_RAND_MAX
const int FST_RAND_MAX
Maximum value fst_rand() can return; use instead of the libc macro RAND_MAX.
Definition
fst_rand.hpp:101
FST::_fst_rand_state
unsigned int & _fst_rand_state()
LCG state, one instance per thread; each thread starts from the default state 1.
Definition
fst_rand.hpp:87
Generated by
1.17.0