Skip to content

Instantly share code, notes, and snippets.

@Riateche
Created July 3, 2012 10:19
Show Gist options
  • Save Riateche/3038910 to your computer and use it in GitHub Desktop.
Save Riateche/3038910 to your computer and use it in GitHub Desktop.
Item drop_random_item() {
int r = rand(0, total_chance_sum);
int current_sum = 0;
for(int i = 0; i < items.count(); i++) {
if (current_sum <= r && r < current_sum + items[i].chance) return items[i];
current_sum += items[i].chance;
}
}
@frops
Copy link

frops commented Sep 30, 2014

Thank you!

@Ficksik
Copy link

Ficksik commented May 31, 2019

Thank you!

@x2PI-Dev
Copy link

x2PI-Dev commented Nov 4, 2020

Дружище, можешь объяснить как это работает?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment