Help designing restricted randomness

afisakov

You can change this now in User CP.
I am working on a map that has several bosses drop a random class-specific drop. Since there are 12 classes there is a 1/12 chance that a drop for your class will randomly appear and these bosses respawn.
However, in reality the nature of rng makes it that killing the same boss 12x does not guarantee you will get your drop and can sometimes take over 20 attempts.
(11/12)^12 has a 35% chance of not dropping what you want
(11/12)^20 has 17.5% chance of still failing which feels horrible to players
SO what I am trying to do is use hashtables to build a 'memory' into the drop trigger so it cannot repeat any of the last 6 drops. That way if you fail a couple of times the odds of a success start going up and getting 12+ fails becomes alot less likely.
Unfortunately it does not seem to be working properly and sometimes drops no item or repeats an item within 6 attempts. I posted the code below and am looking for advice on either fixing my code or how to do this better.
Thanks in advance for the help.
Code:
 function Charspecificdrop takes integer gtype, real x, real y returns nothing
local integer i=1
local integer rand=GetRandomInt(1,12)
loop
   exitwhen i>6
   if LoadInteger(rv,6,gtype*10+i)==rand then
       set rand=GetRandomInt(1,12)
       set i=0
       call DisplayTextToPlayer(GetLocalPlayer(),0,0,"rerolled drop")
   endif
   set i=i+i
endloop
set i=LoadInteger(rv,6,gtype*10+9)
if i<1 or i>5 then
set i=1
else
set i=i+1
endif
call SaveInteger(rv,6,gtype*10+9,i)
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"drop # "+I2S(i)+", r "+I2S(rand))
call SaveInteger(rv,6,gtype*10+i,rand)
call CreateItem(jX[LoadInteger(rv,6,gtype*10)+rand],x,y)
endfunction
on initialize
Code:
set i=0
loop
   exitwhen i>40
   call SaveInteger(rv,6,i,0)
   set i=i+1
endloop
call SaveInteger(rv,6,0,350-1) //refers to original spots in array that random item spawned from
call SaveInteger(rv,6,10,260-1)
call SaveInteger(rv,6,20,275-1)
call SaveInteger(rv,6,30,335-1)
 

jonas

Well-Known Member
When you do not drop an item, does it display a lot of rerolls?

When it drops the same item again, is the displayed rand value also the same as in the last 6 drops?

I can't find any correctness problem in your code.

I believe either jX is misconfigured (duplicates? wrong index? zeros?), and/or you are running over the operation limit, and/or the hashtable is buggy.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    seeing some weird stuff doing some moves to the new Weird News forum please see the bathroom admins
  • The Helper The Helper:
    :) it is weird
  • The Helper The Helper:
    btw it was just lag the weirdness is gone
  • Wizard Wizard:
    I checked!
    +1
  • Blackveiled Blackveiled:
    How is everyone doing?
  • Wizard Wizard:
    Alright!
  • The Helper The Helper:
    Doing well thanks!
  • The Helper The Helper:
    Tom Mai check out the post I just found you made in 2006, from an apparent banned account, I do not remember that happening, the post is in the General Discussion Hall of Fame about record breakers
  • Blackveiled Blackveiled:
    Lmao thats somethin right there.
  • tom_mai78101 tom_mai78101:
    How far back were you looking at?
  • tom_mai78101 tom_mai78101:
    But yes, that was me.
  • The Helper The Helper:
    Do you think I am looking back in the forums for this stuff? LOL, no, I find these posts in the Members Online section or the stats - all these old posts I am bumping and moving around are what people are actually looking at on the website
  • tom_mai78101 tom_mai78101:
    Interesting.
  • The Helper The Helper:
    hey Tom your Burrito news is going viral by TheHelper.net standards LOL
  • The Helper The Helper:
    looks like The Burrito has been shared to facebook lol I am getting the facebook bots in now
  • The Helper The Helper:
    I am going to do one more News Forum like the Weird News but this one is Science News for all the cool science and technology articles in the Archive
  • tom_mai78101 tom_mai78101:
    Hmm, do I need to start posting some of the Science and Technology news to this new section in the future?
  • tom_mai78101 tom_mai78101:
    Or do we need to move the news to their respective sections once the threads are old enough, read to be put into the News Archive?
  • The Helper The Helper:
    The 2nd thing
  • The Helper The Helper:
    I have been moving stuff from the current Headline news like a year old and stuff over when I see it in the logs or members online but mostly I have been moving stuff from the Archives
  • The Helper The Helper:
    It is possible to automate it so that instead of moving to Archive if it has the Science, technology or sci tech tag that it gets archived there instead. I am considering a new Weird News Tag
  • tom_mai78101 tom_mai78101:
    Please do. I'll try to tag the news appropriately when I get the chance.
  • The Helper The Helper:
    The new Discourse forum software we are moving to next does alot with the tags and also hashtags
  • The Helper The Helper:
    OK I found the source of your burrito post stuff it is from Reddit and possibly a facebook post too but definitely reddit

    Staff online

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top