Alex Bikfalvi
SimStream Documentation
ModelBandwidthBins.cpp
00001 #include "Headers.h" 00002 #include "ModelBandwidthBins.h" 00003 #include "Rand.h" 00004 00005 CModelBandwidthBins::CModelBandwidthBins( 00006 __uint32 binsCount, 00007 double* binsFraction, 00008 __bitrate* binsBandwidth 00009 ) 00010 { 00011 this->binsCount = binsCount; 00012 this->binsFraction = binsFraction; 00013 this->binsBandwidth = binsBandwidth; 00014 } 00015 00016 __bitrate CModelBandwidthBins::Bandwidth(__uint32 peer) 00017 { 00018 // Generate a random number 00019 double rnd = CRand::Generate(); 00020 00021 // Find the bin 00022 double sum = 0; 00023 for(unsigned int index = 0; index < this->binsCount; index++) 00024 if(sum + this->binsFraction[index] >= rnd) 00025 return this->binsBandwidth[index]; 00026 else 00027 sum += this->binsFraction[index]; 00028 return this->binsBandwidth[this->binsCount-1]; 00029 }
Last updated: February 8, 2011