HabitRPG / habitica

A habit tracker app which treats your goals like a Role Playing Game.
https://habitica.com
Other
11.83k stars 4.05k forks source link

I get far more of one type of drop than others (eggs or hatching potions or food) #2176

Closed petitato07 closed 10 years ago

petitato07 commented 10 years ago

I'm in a level where I can finally recieve random eggs, potions, and food. When I do my dailies and to-dos, I never seem to have gotten any hatching potions. The eggs and food I got are always the same thing. I wonder if this is a bug of some sort.


edit by admin

There is no known bug with the drop system's choice of items.

The drop system uses a random number generator to control which type of item you get for each drop. Randomness does sometimes produce a long string of seemingly related items, but it's still random. It will balance out over time and you'll end up getting more of the items you're missing now. You can learn more about the Drop system and the frequency of dropped items on the wiki at Drops.

SabreCat commented 10 years ago

What's your user ID (from the Settings > API tab)? And what eggs and food are you consistently getting?

Could conceivably be a problem with predictableRandom, but could just as easily be weird luck :P

SabreCat commented 10 years ago

...now that you mention, I've been getting Wolf Cub Eggs and Meats pretty consistently for the last few days. I'd better keep an eye on it too! :tiger:

lefnire commented 10 years ago

@SabreCat I checked out @petitato07's account, Wolf Cub & Meat as well. Something's up with predictableRandom

SabreCat commented 10 years ago

Ut oh! A trifle too predictable!

djuretic commented 10 years ago

+1 I have got ~10 Meats since the introduction of the mounts feature, my second common food drop is Honey (~4 drops). My most common eggs in the inventory are: Wolf Egg (5) and Panda Egg (5).

lefnire commented 10 years ago

The predictable things works very well in other locations, I think we're using a bad seed for randomVal (the part that selects random keys from an object). I'll look into this soon as I can, but can't get to till tonight

SabreCat commented 10 years ago

Today: Zombie Potion, Meat, Meat, Meat, Honey. So much Meat (and food in general) is a little odd, but nothing too alarming yet.

SabreCat commented 10 years ago

Maybe we can script up one of those 1000-drop simulations?

lefnire commented 10 years ago

take a peek at which seed the randomVal function is using, I have a hunch it's just a poor seed to use, might just be an oversight. We can add some console.logs to the math_samples.coffee file, too. Will join you when I can, lotta stuff for me today

SabreCat commented 10 years ago

I've been getting a decent variety today. Tiger Cub Egg, Red Potion, Skeleton Potion... not reproducible here, it seems.

erratio commented 10 years ago

I'm still getting nigh-infinite wolf eggs, occasional other eggs and potions, no food :(

lorian commented 10 years ago

There does seem to be some kind of skew towards wolf eggs; of the four people I've introduced to Habit in the last month, three of them have gotten no eggs other than wolf eggs (and the fourth hasn't gotten an egg yet). And I have 19 of the damn things. We're basically the Wolf Trainer party at this point. I'm definitely not JUST getting wolf eggs though; I got a meat (lol) and a base potion so far today.

Alys commented 10 years ago

In predictableRandom, there's this code: x = Math.sin(seed++) * 10000 Is it meant to be ++seed instead of seed++ ? As it's written, I think seed is incremented AFTER the sine value is calculated, which seems pointless.

I suspect the ++ is intended for the case where seed happens to be zero, because sin(0) is 0 which would lead to predictableRandom returning 0 (which might not be desirable in some cases?)

Note that this might not have anything to do with the large number of Wolves and Meat people (including me) have been getting. :)

Interesting point: Wolf and Meat are both at the first positions in their arrays in content.coffee. That might (or might not) help track down a bug, if one exists.

Alys commented 10 years ago

Also in predictableRandom, does it matter that user.stats isn't an array of numbers? (At least I don't think it is.) I'm not very familiar with JavaScript so I'm having trouble wrapping my head around some of the code, but it looks as if the _reduce callback is expecting a simple array of integers. And that's my final comment because I don't really know what I'm talking about. :) I'm hoping to learn though.

lefnire commented 10 years ago

The actual predictableRandom function, which we got from a utils library somewhere, is not likely to be the issue. Which seed we're using is much more likely. So your second comment about user.stats not being a collection of numbers is a more likely lead than the seed++ thing, I'll look into

mariahm commented 10 years ago

I've got my account and my party's member's experiencing a ridiculous number of wolf eggs, and some tiger eggs. No other eggs at all, for at least 3 days, though I am getting potions and some food drops. A lot more meat than any other food drops, but nowhere near the same extent as whats going on with the eggs.

In case it helps, here's my UUID, as you asked for someone else's upthread: 12048ccf-3bd7-47fd-8256-ff811210e24c

brightbold commented 10 years ago

Egg drops are still looking pretty Wolfy. My gut is that food drops are less overwhelmingly Meaty than egg drops are Wolfy, but that might just be my imagination (since I'm happy to get any food drop at all, but all the egg drops piss me off due to their failure to be gold hatching potions. Sorry, off-topic. My Beastmaster woes are not at issue here...)

MAZimbric commented 10 years ago

I'm also getting Wolf Eggs to the near exclusion of all others, and food drops heavily on the meat.

colegleason commented 10 years ago

So we seem to be using user.stats.gp to seed rarity. Not sure why that would be an issue.

colegleason commented 10 years ago

I simulated 10,000 drops and this is what I got:

{ type: { Egg: 3003, HatchingPotion: 3040, Food: 3958 },
  LionCub: 160,
  Base: 607,
  Wolf: 1496,
  Zombie: 268,
  Meat: 1988,
  Desert: 418,
  Milk: 662,
  Red: 471,
  Strawberry: 177,
  Potatoe: 336,
  Shade: 137,
  FlyingPig: 64,
  Golden: 323,
  White: 204,
  BearCub: 339,
  Skeleton: 302,
  Honey: 407,
  TigerCub: 481,
  Fox: 109,
  Fish: 95,
  PandaCub: 258,
  CottonCandyPink: 163,
  Cactus: 52,
  CottonCandyBlue: 251,
  Chocolate: 126,
  RottenMeat: 63,
  Dragon: 44 }

So the actual type of drop isn't the issue, but rather the result from randomVal which uses (in this case) the default seed for predictableRandom.

lorian commented 10 years ago

Wow, no wonder I never see dragon eggs!

colegleason commented 10 years ago

I messed around with randomVal. It's the problem function, not predictable random.

randomVal: (obj, options) -> 
    _.sample(_.values(obj))
{ type: { HatchingPotion: 2985, Food: 4040, Egg: 2976 },
  Skeleton: 305,
  CottonCandyPink: 588,
  RottenMeat: 432,
  CottonCandyBlue: 558,
  Fish: 414,
  Dragon: 358,
  Wolf: 359,
  FlyingPig: 346,
  Fox: 321,
  BearCub: 306,
  Honey: 409,
  Chocolate: 400,
  Strawberry: 386,
  Golden: 316,
  TigerCub: 338,
  LionCub: 331,
  Meat: 407,
  White: 398,
  Desert: 388,
  Potatoe: 415,
  Base: 418,
  Shade: 298,
  Red: 291,
  Milk: 414,
  PandaCub: 297,
  Zombie: 188,
  Cactus: 320 }
randomVal: (obj, options) -> 
    rand = user.fns.predictableRandom(options?.seed)                                                                               
    _.values(obj)[Math.floor(rand*_.values(obj).length)] 
{ type: { Food: 4010, HatchingPotion: 2958, Egg: 3033 },
  CottonCandyPink: 629,
  White: 395,
  Milk: 381,
  RottenMeat: 389,
  BearCub: 339,
  CottonCandyBlue: 558,
  Wolf: 322,
  Desert: 387,
  Potatoe: 395,
  LionCub: 335,
  Red: 309,
  Golden: 315,
  Chocolate: 413,
  Cactus: 346,
  PandaCub: 340,
  Fish: 428,
  FlyingPig: 333,
  TigerCub: 331,
  Zombie: 206,
  Base: 393,
  Strawberry: 417,
  Fox: 335,
  Meat: 385,
  Dragon: 352,
  Skeleton: 292,
  Honey: 407,
  Shade: 269 }

This is our source for our current randomVal function. I don't know why it is wrong yet. It's worth noting that items who come first in the object's keys (Wolf, Meat) have a higher drop value.

colegleason commented 10 years ago

So I've been staring at this trying to figure out what the hell is wrong with this function. After consulting the sacred tome (The Art of Computer Programming, Volume 2) in a dark place on the internets, I found that this algorithm is called Reservoir Sampling. Here is a writeup.

The problem? predictableRandom runs with the standard seed for the entire sequence of randomVal. The standard seed is the sum of user.stats. They never change during the scope of randomVal (nor would it for any seed you passed it). I think the solution is to either rewrite randomVal to just be _.shuffle(_.values(obj)) or to pass randomVal a seed function of some sort.

SabreCat commented 10 years ago

Brilliant work, @colegleason!

lefnire commented 10 years ago

Did you get a chance to run your sims against the new function @colegleason ? I started to write some tests, and thought "how does one write tests for random? eh whatever, I'll just ask him if he gave it some runs"

colegleason commented 10 years ago

I did and it's fine. Don't have the output handy for you though.

You can test random functions to make sure the results lie within some variance. Tests might fail every now and then though.

On Wed, Jan 15, 2014 at 7:19 PM, Tyler Renelle notifications@github.comwrote:

Did you get a chance to run your sims against the new function @colegleason https://github.com/colegleason ? I started to write some tests, and thought "how does one write tests for random? eh whatever, I'll just ask him if he gave it some runs"

— Reply to this email directly or view it on GitHubhttps://github.com/HabitRPG/habitrpg/issues/2176#issuecomment-32433915 .

Cole Gleason

Student, University of Illinois at Urbana-Champaign Email: cg@colegleason.com Website: colegleason.com

lefnire commented 10 years ago

:+1:

Biondom commented 9 years ago

I am currently experiencing this issue--receiving tons of eggs but no hatching potions. What should I do? Reopen it as a new issue?

Alys commented 9 years ago

@Biondom It's just random chance. We have many thousands of players, and the nature of randomness means that some will get long runs of one item only. You're one of the unlucky ones at the moment, but in future you'll get hatching potions too.

Alys commented 9 years ago

@Biondom Sorry, to be more specific, there have been bugs in the past where the balance of drops wasn't correct, but we believe there aren't any now. Other players are getting hatching potions (I had one a few minutes ago), so there is no bug stopping them happening.

Biondom commented 9 years ago

Oops, started new issue before I saw this (I was subscribed to this thread, so not sure how I missed your responses.)

Thanks for letting me know. I guess I will just wait and see.

beeflin commented 8 years ago

Surely, if the random number generator is truly random, it is possible to get a infinitely long streak without an essential item? It would happen to a few people and spoil the game for them. I'm waiting to see whether I'm one of those people (many eggs, few potions). But if I were setting the frequency of drops I would make it slightly non-random to eliminate this possibility. Is this not a good idea for some reason I don't know (I am after all a newbie)?

khipkin commented 8 years ago

tl;dr If the random number generator is truly random, no one's game will be spoiled.


"It is possible to get an infinitely long streak"

Things can be technically "possible" but with such a negligible probability that they may as well be impossible.

For example, GUIDs are "unique", but it is technically possible to generate the same GUID twice. It's just so so so unlikely that we assume it will never happen. If it ever did, the universe would probably implode or something.

While each generated GUID is not guaranteed to be unique, the total number of unique keys (2^128 or 3.4×10^38) is so large that the probability of the same number being generated twice is very small. For example, consider the observable universe, which contains about 5×10^22 stars; every star could then have 6.8×10^15 universally unique GUIDs.

(From StackOverflow, and originally from Wikipedia, but it must have been removed since the quote was taken.)

lizgzil commented 8 years ago

I guess this is an old issue, but I really think my drops aren't random.

I've had 12 food items, 4 potions, and 19 eggs so far. So based on the drop probabilities of 0.4, 0.3 and 0.3 respectively for food, potions and eggs, I think the drop numbers I have experienced or more extreme than these would occur with probabilities of 31% (fine), 0.9% and 0.2%. This is based on the distributions of the outputs of 35 random drops, done 100,000 times (see graph). So I don't think this is just unlucky, it's likely to not be random.

In an attempt to be constructive, although definitely not an expert, here are my amateur and probably patronising suggestions. It seems that it must be something to do with seeding your random numbers from "user.stats.gp". Perhaps a rounding issue with more likely numbers of gold points - perhaps multiples of 2 or 5 are more likely, and this in some way messes up the random number seed? Also, perhaps something to do with the fact that the maximum number of gold points changes with which level you are at.

dropprobs_basedon100000sims
crookedneighbor commented 8 years ago

FYI, since the random drops on longer need to be calculated on the client, there's already work underway to remove the seeding and just have the server determine what the drops will be.

lizgzil commented 8 years ago

Thanks @crookedneighbor! Hopefully an influx of potions will come my way soon then.

Jacqland commented 7 years ago

I'm happy to have found this (I'm also in the 30s levels, 56/90 pets found, maxed perception, no flying pig eggs). Hopefully they'll show up soon. I was beginning to suspect the flying pigs were intended to make me spend RL$.

texastoland commented 6 years ago

[@Alys] We have many thousands of players, and the nature of randomness means that some will get long runs of one item only.

Before choosing a class I had a long string of eggs without potions. This week I've found 16 potions without eggs. Even if it's theoretically random it's distribution appears off.

[@SabreCat] Maybe we can script up one of those 1000-drop simulations?

This sounds like a sensible unit test to measure deviation if it doesn't already exist?