Skip to content

Instantly share code, notes, and snippets.

@naan
Created July 6, 2010 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naan/464861 to your computer and use it in GitHub Desktop.
Save naan/464861 to your computer and use it in GitHub Desktop.
long randNum = random();
int dart = randNum % totalPercent;
int tempTotal = 0;
AdWhirlAdNetworkConfig *result = nil;
for (AdWhirlAdNetworkConfig *network in prioritizedAdNetworks) {
tempTotal += network.trafficPercentage;
if (dart < tempTotal) {
// this is the one to use.
result = network;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment