83 #if defined(NCBI_OS_UNIX) || defined(NCBI_OS_DARWIN)
85 #include <sys/types.h>
90 #elif defined(NCBI_OS_MSWIN)
100 #if defined(NCBI_OS_UNIX) || defined(NCBI_OS_DARWIN)
124 {
return m_Fd != -1; }
130 "System-dependent generator is not available");
142 string(
"Error getting random value from the "
143 "system-dependent generator: ") +
152 #elif defined(NCBI_OS_MSWIN)
158 m_Provider(0), m_Initialized(
false)
160 static DWORD providers[] =
161 { PROV_RSA_AES, PROV_RSA_FULL, PROV_RSA_SIG,
162 PROV_RSA_SCHANNEL, PROV_DSS, PROV_DSS_DH,
163 PROV_DH_SCHANNEL, PROV_FORTEZZA,
164 PROV_MS_EXCHANGE, PROV_SSL };
165 for (
size_t k = 0; k <
sizeof(providers)/
sizeof(providers[0]); ++k) {
166 if (CryptAcquireContext(&m_Provider, 0, 0, providers[k],
167 CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
168 m_Initialized =
true;
176 CryptReleaseContext(m_Provider, 0);
177 m_Initialized =
false;
182 {
return m_Initialized; }
188 reinterpret_cast<PBYTE
>(
value)))
191 if (throw_on_error) {
194 "System-dependent generator is not available");
197 string(
"Error getting random value from the "
198 "system-dependent generator. Error code: ") +
205 HCRYPTPROV m_Provider;
221 "System-dependent generator is not available");
228 m_RandMethod(eGetRand_LFG)
238 "CRandom::Reset() is not allowed for "
239 "system-dependent generator");
243 0xd53f1852, 0xdfc78b83, 0x4f256096, 0xe643df7,
244 0x82c359bf, 0xc7794dfa, 0xd5e9ffaa, 0x2c8cb64a,
245 0x2f07b334, 0xad5a7eb5, 0x96dc0cde, 0x6fc24589,
246 0xa5853646, 0xe71576e2, 0xdae30df, 0xb09ce711,
247 0x5e56ef87, 0x4b4b0082, 0x6f4f340e, 0xc5bb17e8,
248 0xd788d765, 0x67498087, 0x9d7aba26, 0x261351d4,
249 0x411ee7ea, 0x393a263, 0x2c5a5835, 0xc115fcd8,
250 0x25e9132c, 0xd0c6e906, 0xc2bc5b2d, 0x6c065c98,
291 "CRandom::SetSeed(...) is not allowed for "
292 "system-dependent generator");
316 "CRandom::GetSeed(...) is not allowed for "
317 "system-dependent generator");
340 while (
size <<= 1 ) {
350 }
while ( bits >
r -
size );
Exceptions generated by CRandom class.
bool IsInitialized(void) const
bool GetRand(CRandom::TValue *value, bool throw_on_error)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
uint32_t Uint4
4-byte (32-bit) unsigned integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
static TPid GetPid(void)
Get process identifier (pid) for the current process.
TValue m_State[kStateSize]
Uint4 TValue
Type of the generated integer value and/or the seed value.
EGetRandMethod m_RandMethod
TValue GetRand(void)
Get the next random number in the interval [0..GetMax()] (inclusive)
TValue GetRandIndex(TValue size)
Get random number in the interval [0..size-1] (e.g.
Uint8 GetRandUint8(void)
Get random Uint8 number.
Uint8 GetRandIndexUint8(Uint8 size)
Get random number in the interval [0..size-1] (e.g.
CRandom(EGetRandMethod method=eGetRand_LFG)
If "method" is:
TValue GetSeed(void) const
Get the last set seed (LFG only)
void SetSeed(TValue seed)
Seed the random number generator with "seed".
EGetRandMethod
Random generator to use in the GetRand() functions.
void Reset(void)
Reset random number generator to initial startup condition (LFG only)
void Randomize(void)
Re-initialize (re-seed) the generator using platform-specific randomization.
TValue x_GetSysRand32Bits(void) const
@ eGetRand_Sys
Use system-dependent random generator.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
long NanoSecond(void) const
Get nano-seconds.
int Second(void) const
Get second.
@ eCurrent
Use current time. See also CCurrentTime.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Defines process management classes.
Static variables safety - create on demand, destroy on application termination.
Defines NCBI C++ diagnostic APIs, classes, and macros.
Multi-threading – classes, functions, and features.
Defines: CTimeFormat - storage class for time format.
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static CSafeStatic< CRandomSupplier > s_RandomSupplier
static const char * kHardwareGeneratorDevice
static const char * kSoftwareGeneratorDevice
static const size_t kStateOffset