# 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
set rand=GetRandomInt(1,12)
set i=0
call DisplayTextToPlayer(GetLocalPlayer(),0,0,"rerolled drop")
endif
set i=i+i
endloop
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)
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)``````

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:
time slowed down once i quit smoking though I have been quit smoking for 3 weeks for like 3 weeks lol
+1
• The Helper:
so then it is 3 more weeks on the same level patch i am on then switch to the lower one. Originally I quit on the step 2 lower patch but started doubling it when I got cravings so I finally started with the right doseage
• The Helper:
It will be 3 weeks in 2 days I think
+1
• The Helper:
so funny in my work text stream I dropped all your base are belong to us like it was supposed to be there lol
• The Helper:
958 online ai bots lol
+1
• jonas:
• jonas:
• The Helper:
1110 users online
• The Helper:
my dad used to be on the site back in the mid 2000s during the start of the World Editor forum in the SD Ryoko days he was the The Small Business Helper - we did a little website for him and he had a forum on here for a while. In the end when he started to get confused he would sometimes refer to himself as The Helper where he was getting me and him mixed up
+1
• The Helper:
He was always proud of this site
+1
• Varine:
I have a couple teeth I need to get removed and implants in, and I still have my wisdom teeth so they want to take those as well. Not as invasive as yours, but I'm not looking forward to it. I was told it would be like three or four days before they start to close and like a month or so for it to fully heal. I also am going to have to quit smoking for that. I got these toothpick things to try, but idk if I just got really cheap ones or what but I keep getting splinters in my lips
• The Helper:
the patch has worked for me on the stop smoking so far - I am still on the first level of patch though which is still full of nicotine and I have not been having hardly any cravings
• Varine:
I'm averse to the patches for some reason. I also tried the gum but I'm not very good at not chewing on it, so I just get myself sick
• Blackveiled:
I actually quit smoking cigarettes by switching to vaping. But I weaned myself by the mg, and on top of that it actually just made cigarettes taste and smell disgusting. I probably actually was totally done smoking/vaping roughly 4-5 months after I first got the vape. But I really attribute the vape mainly to making cigarettes basically repulsive.
• Varine:
Vapes make me cough
• The Helper:
I dont like vaping - the only vaping I do is this THC Concentrate - you only take like 2 puffs on it though and it kills the lungs that is for sure. Otherwise, this patch is working out for me - obviously, I am not a candidate for the gum having no teeth now and all LOL
• Varine:
I really wanted the toothpicks to work out, but the splinters are a fucking no go.
• Varine:
I might try to find some different ones once I get through August. This month is not off to a great start.
• The Helper:
man the bots are just raping all of our public data lol
• The Helper:
1376 bots now lol