Feature Selection Toolbox FST4
UTIA · Czech Academy of Sciences
Loading...
Searching...
No Matches
fst_rand.hpp
Go to the documentation of this file.
1#ifndef FSTFSTRAND_H
2#define FSTFSTRAND_H
3 /*
28=========================================================================
29Copyright 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
50namespace FST {
51
85
87inline unsigned int& _fst_rand_state() { static thread_local unsigned int s = 1; return s; }
88
90inline void fst_srand(unsigned int seed) { _fst_rand_state() = seed; }
91
93inline int fst_rand()
94{
95 unsigned int& s = _fst_rand_state();
96 s = s * 214013u + 2531011u;
97 return (int)((s >> 16) & 0x7fff);
98}
99
101const int FST_RAND_MAX = 32767;
102
112inline 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
The Feature Selection Toolbox 4 library: every library component – data access, criteria and classifi...
Definition data_accessor.hpp:80
void fst_srand(unsigned int seed)
Seeds the calling thread's FST4 PRNG; use instead of std::srand().
Definition fst_rand.hpp:90
int fst_rand()
Returns the next pseudo-random draw in 0..FST_RAND_MAX; use instead of std::rand().
Definition fst_rand.hpp:93
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
const int FST_RAND_MAX
Maximum value fst_rand() can return; use instead of the libc macro RAND_MAX.
Definition fst_rand.hpp:101
unsigned int & _fst_rand_state()
LCG state, one instance per thread; each thread starts from the default state 1.
Definition fst_rand.hpp:87
Copyright © 2000–present ÚTIA, Institute of Information Theory and Automation of the Czech Academy of Sciences · Contacts · This site sets no cookies and uses no analytics.