What's the best way to code for random loot?

Hello, I’m new to Panda and rather new to Python but not stranger to programing. However, i only had basic training in VB.

I’m currently reading python programing for absolute beginers, and I find programing in python addictive.

My question is, what’s the best way to implement a random loot system?
I tried with random.randrange and random.choice, they both well but what if i wan to limit certain loots? Like common loots drop more frequently than rare.

I want to create a small rpg for private use, nothing fancy. Just a character hacking few mobs with random drops, no networking.

Thank you. I hope I made my first post clear enough.

Hey mate,

There’s a few ways you can go about this. The easiest (IMHO) is to generate a random number between 1-1000, with ranges between 1-499 being common items, 500-799 being uncommon items, 800-899 being rare items, 900-949 for super rare items, 950-989 for ultra rare items, 990-1000 for zomg rare items, etc.

Thanks Sasayaki, I’ll be playing around with the idea of random number gen. For curiosity, what are the other ways to do it?


Other ways include static drops and algorithms. If you are making the game online, you will have to have the server do this, not the client.

Static drops: items that will always drop
Algorithm: items base on # of kills or combination of random and an algorithm.

kills * %(1-100) = x
if x = 10
BobInv.add(god item)

kills * random number = x
if x = 10
BobInv.add(god item)

Thanks for the tip adr,
Yes, i will eventually make my game online, this way of doing random drops for rare items with algorithms sounds good.