DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
/* boost random/uniform_smallint.hpp header file * * Copyright Jens Maurer 2000-2001 * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org for most recent version including documentation. * * $Id: uniform_smallint.hpp 41369 2007-11-25 18:07:19Z bemandawes $ * * Revision history * 2001-04-08 added min
#include
#include
#include
#include
#include
#include
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS #include
#endif namespace boost { // uniform integer distribution on a small range [min, max] namespace detail { template
InputStream& extract_uniform_int(InputStream& is, UniformInt& ud, Impl& impl) { typename UniformInt::result_type min, max; is >> std::ws >> min >> std::ws >> max; impl.set(min, max); return is; } template
struct uniform_smallint_integer { public: typedef UniformRandomNumberGenerator base_type; typedef IntType result_type; uniform_smallint_integer(base_type & rng, IntType min_arg, IntType max_arg) : _rng(&rng) { set(min_arg, max_arg); } void set(result_type min, result_type max); result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } base_type& base() const { return *_rng; } result_type operator()() { // we must not use the low bits here, because LCGs get very bad then return (((*_rng)() - (_rng->min)()) / _factor) % _range + _min; } private: typedef typename base_type::result_type base_result; base_type * _rng; IntType _min, _max; base_result _range; base_result _factor; }; template
void uniform_smallint_integer
:: set(result_type min_arg, result_type max_arg) { _min = min_arg; _max = max_arg; assert(min_arg < max_arg); _range = static_cast
(_max-_min)+1; _factor = 1; // LCGs get bad when only taking the low bits. // (probably put this logic into a partial template specialization) // Check how many low bits we can ignore before we get too much // quantization error. base_result r_base = (_rng->max)() - (_rng->min)(); if(r_base == (std::numeric_limits
::max)()) { _factor = 2; r_base /= 2; } r_base += 1; if(r_base % _range == 0) { // No quantization effects, good _factor = r_base / _range; } else { // carefully avoid overflow; pessimizing heree for( ; r_base/_range/32 >= _range; _factor *= 2) r_base /= 2; } } template
class uniform_smallint_float { public: typedef UniformRandomNumberGenerator base_type; typedef IntType result_type; uniform_smallint_float(base_type & rng, IntType min_arg, IntType max_arg) : _rng(rng) { // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope #if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300) BOOST_STATIC_ASSERT(std::numeric_limits
::is_integer); BOOST_STATIC_ASSERT(!std::numeric_limits
::is_integer); #endif assert(min_arg < max_arg); set(min_arg, max_arg); } void set(result_type min_arg, result_type max_arg) { _min = min_arg; _max = max_arg; _range = static_cast
(_max-_min)+1; } result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } base_type& base() const { return _rng.base(); } result_type operator()() { return static_cast
(_rng() * _range) + _min; } private: typedef typename base_type::result_type base_result; uniform_01
_rng; IntType _min, _max; base_result _range; }; } // namespace detail template
class uniform_smallint { public: typedef IntType input_type; typedef IntType result_type; explicit uniform_smallint(IntType min_arg = 0, IntType max_arg = 9) : _min(min_arg), _max(max_arg) { #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope BOOST_STATIC_ASSERT(std::numeric_limits
::is_integer); #endif } result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } void reset() { } template
result_type operator()(Engine& eng) { typedef typename Engine::result_type base_result; base_result _range = static_cast
(_max-_min)+1; base_result _factor = 1; // LCGs get bad when only taking the low bits. // (probably put this logic into a partial template specialization) // Check how many low bits we can ignore before we get too much // quantization error. base_result r_base = (eng.max)() - (eng.min)(); if(r_base == (std::numeric_limits
::max)()) { _factor = 2; r_base /= 2; } r_base += 1; if(r_base % _range == 0) { // No quantization effects, good _factor = r_base / _range; } else { // carefully avoid overflow; pessimizing heree for( ; r_base/_range/32 >= _range; _factor *= 2) r_base /= 2; } return ((eng() - (eng.min)()) / _factor) % _range + _min; } #if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) template
friend std::basic_ostream
& operator<<(std::basic_ostream
& os, const uniform_smallint& ud) { os << ud._min << " " << ud._max; return os; } template
friend std::basic_istream
& operator>>(std::basic_istream
& is, uniform_smallint& ud) { # if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC > 1300 return detail::extract_uniform_int(is, ud, ud._impl); # else is >> std::ws >> ud._min >> std::ws >> ud._max; return is; # endif } #endif private: result_type _min; result_type _max; }; } // namespace boost #endif // BOOST_RANDOM_UNIFORM_SMALLINT_HPP
uniform_smallint.hpp
Page URL
File URL
Prev
26/28
Next
Download
( 6 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.