Skip to content

Instantly share code, notes, and snippets.

@Riateche
Created July 3, 2012 10:19
Show Gist options
  • Select an option

  • Save Riateche/3038910 to your computer and use it in GitHub Desktop.

Select an option

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

frops commented Sep 30, 2014

Copy link
Copy Markdown

Thank you!

@Ficksik

Ficksik commented May 31, 2019

Copy link
Copy Markdown

Thank you!

@x2PI-Dev

x2PI-Dev commented Nov 4, 2020

Copy link
Copy Markdown

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

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