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_int.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_int.hpp 43713 2008-03-19 00:02:06Z marshall $ * * Revision history * 2001-04-08 added min
#include
#include
#include
#include
#include
#include
#include
#ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS #include
#endif namespace boost { // uniform integer distribution on [min, max] template
class uniform_int { public: typedef IntType input_type; typedef IntType result_type; typedef typename random::detail::make_unsigned
::type range_type; explicit uniform_int(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 assert(min_arg <= max_arg); init(); } result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _min; } result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return _max; } void reset() { } // can't have member function templates out-of-line due to MSVC bugs template
result_type operator()(Engine& eng) { typedef typename Engine::result_type base_result; // ranges are always unsigned typedef typename random::detail::make_unsigned
::type base_unsigned; const base_result bmin = (eng.min)(); const base_unsigned brange = random::detail::subtract
()((eng.max)(), (eng.min)()); if(_range == 0) { return _min; } else if(brange == _range) { // this will probably never happen in real life // basically nothing to do; just take care we don't overflow / underflow base_unsigned v = random::detail::subtract
()(eng(), bmin); return random::detail::add
()(v, _min); } else if(brange < _range) { // use rejection method to handle things like 0..3 --> 0..4 for(;;) { // concatenate several invocations of the base RNG // take extra care to avoid overflows range_type limit; if(_range == (std::numeric_limits
::max)()) { limit = _range/(range_type(brange)+1); if(_range % range_type(brange)+1 == range_type(brange)) ++limit; } else { limit = (_range+1)/(range_type(brange)+1); } // We consider "result" as expressed to base (brange+1): // For every power of (brange+1), we determine a random factor range_type result = range_type(0); range_type mult = range_type(1); while(mult <= limit) { result += random::detail::subtract
()(eng(), bmin) * mult; mult *= range_type(brange)+range_type(1); } if(mult == limit) // _range+1 is an integer power of brange+1: no rejections required return result; // _range/mult < brange+1 -> no endless loop result += uniform_int
(0, _range/mult)(eng) * mult; if(result <= _range) return random::detail::add
()(result, _min); } } else { // brange > range if(brange / _range > 4 /* quantization_cutoff */ ) { // the new range is vastly smaller than the source range, // so quantization effects are not relevant return boost::uniform_smallint
(_min, _max)(eng); } else { // use rejection method to handle cases like 0..5 -> 0..4 for(;;) { base_unsigned result = random::detail::subtract
()(eng(), bmin); // result and range are non-negative, and result is possibly larger // than range, so the cast is safe if(result <= static_cast
(_range)) return random::detail::add
()(result, _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_int& ud) { os << ud._min << " " << ud._max; return os; } template
friend std::basic_istream
& operator>>(std::basic_istream
& is, uniform_int& ud) { # if BOOST_WORKAROUND(_MSC_FULL_VER, BOOST_TESTED_AT(13102292)) && BOOST_MSVC == 1400 return detail::extract_uniform_int(is, ud, ud.impl); # else is >> std::ws >> ud._min >> std::ws >> ud._max; ud.init(); return is; # endif } #endif private: void init() { _range = random::detail::subtract
()(_max, _min); } // The result_type may be signed or unsigned, but the _range is always // unsigned. result_type _min, _max; range_type _range; }; } // namespace boost #endif // BOOST_RANDOM_UNIFORM_INT_HPP
uniform_int.hpp
Page URL
File URL
Prev
23/28
Next
Download
( 5 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.