Help with iRandom percentages

Post » Mon Jun 01, 2015 9:55 pm

I can't wrap my head around how iRandom percentages work. It's probably easy, but my brain melts when I try to add it up correctly, so I guess I don't understand how it works. Anyway, I have 12 items that should be randomly distributed.

1 should be rather common, so perhaps 15%

7 are alike in values so perhaps 10% each

That leaves 15% for the remaining 4 items, that should be progressively more rare, so like: 1%, 3%, 4%, 7%.

Here's how it looks right now, but is it correct?:

set iRandom to Rand 1 101						if iRandom <= 15							rTarget.AddItem DNCDogtagsF 1							rTarget.EquipItem DNCDogtagsF						elseif iRandom <= 25							rTarget.AddItem DNCIronF 1							rTarget.EquipItem DNCIronF						if iRandom <=35							rTarget.AddItem DNCBrahminM 1							rTarget.EquipItem DNCBrahminM						elseif iRandom <=45							rTarget.AddItem DNCDogtagsM 1							rTarget.EquipItem DNCDogTagsM						elseif iRandom <=55							rTarget.AddItem DNCGearM 1							rTarget.EquipItem DNCGearM						elseif iRandom <=65							rTarget.AddItem DNCKeyM 1							rTarget.EquipItem DNCKeyM						elseif iRandom <=75							rTarget.AddItem DNCSkullM 1							rTarget.EquipItem DNCSkullM						elseif iRandom <=85							rTarget.AddItem DNCCopperF 1							rTarget.EquipItem DNCCopperF						elseif iRandom <=93							rTarget.AddItem DNCSilverF 1							rTarget.EquipItem DNCSilverF						elseif iRandom <=96							rTarget.AddItem DNCGoldF 1							rTarget.EquipItem DNCGoldF						elseif iRandom <=97							rTarget.AddItem DNCWhitePearlF 1							rTarget.EquipItem DNCWhitePearlF						elseif iRandom <=100							rTarget.AddItem DNCBlackPearlF 1							rTarget.EquipItem DNCBlackPearlF
User avatar
Ray
 
Posts: 3472
Joined: Tue Aug 07, 2007 10:17 am

Post » Mon Jun 01, 2015 7:36 pm

With using the comparable of "<=" doesn't that make every line below the random number become true.

So the first item with "<= 15" will always be equiped .... and if the random number is 100 , then all items will be equiped?

Is this what you intended ?

User avatar
My blood
 
Posts: 3455
Joined: Fri Jun 16, 2006 8:09 am

Post » Mon Jun 01, 2015 10:59 pm

Thanks, but that can't be it. This is how it looks now:

set iRandom to Rand 1 101						if iRandom <= 35							rTarget.AddItem DNCDogtagsF 1							rTarget.EquipItem DNCDogtagsF						elseif iRandom <= 55							rTarget.AddItem DNCIronF 1							rTarget.EquipItem DNCIronF						elseif iRandom <=70							rTarget.AddItem DNCCopperF 1							rTarget.EquipItem DNCCopperF						elseif iRandom <=80							rTarget.AddItem DNCSilverF 1							rTarget.EquipItem DNCSilverF						elseif iRandom <=90							rTarget.AddItem DNCGoldF 1							rTarget.EquipItem DNCGoldF						elseif iRandom <=96							rTarget.AddItem DNCWhitePearlF 1							rTarget.EquipItem DNCWhitePearlF						elseif iRandom <=100							rTarget.AddItem DNCBlackPearlF 1							rTarget.EquipItem DNCBlackPearlF						endif					endif				endif			elseif (rTarget.GetIssix Male)				if (rTarget.GetDisabled) || (rTarget.GetDead)					else					set rNPCNecklace to rNPCNecklace.GetEquippedObject 8					set rNPCChoker to rNPCChoker.GetEquippedObject 15					if (rNPCNecklace == 0) && (rNPCChoker == 0) && (rTarget.GetItemCount DNCNecklaceFlag == 0)						rTarget.AddItem DNCNecklaceFlag 1						rTarget.AddItem DNCResetFlag 1						set iRandom to Rand 1 101						if iRandom <=20							rTarget.AddItem DNCBrahminM 1							rTarget.EquipItem DNCBrahminM						elseif iRandom <=40							rTarget.AddItem DNCDogtagsM 1							rTarget.EquipItem DNCDogTagsM						elseif iRandom <=60							rTarget.AddItem DNCGearM 1							rTarget.EquipItem DNCGearM						elseif iRandom <=80							rTarget.AddItem DNCKeyM 1							rTarget.EquipItem DNCKeyM						elseif iRandom <=100							rTarget.AddItem DNCSkullM 1							rTarget.EquipItem DNCSkullM

And it works fine. DogTags are most common for females, Black Pearls very rare (so elseif iRandom <=100 equals 1 percents chance). And for males all different pendants are equally common.

The thing is that I want to remove males altogether, but add those pendants to the female random list instead.

Guess it works like a dice with 100 (101?) sides, so if you cast 100, you get the Black Pearls. If you cast 96-99, you get the White Pearls etc. But that's the issue - I'm not sure exactly how it works...

EDIT: The "if" before iRandom <=35 in my first post should be removed. Paste error. Interestingly, my game became extremely unstable with my edited script. Freezes and crashes constantly. So something is up with it.

User avatar
Lucie H
 
Posts: 3276
Joined: Tue Mar 13, 2007 11:46 pm

Post » Mon Jun 01, 2015 10:34 pm

"Guess it works like a dice with 100 (101?) sides"

Yes thats exactly how it works. I just didn't expect it to work properly without for example :

If irandom >= 16 && <= 25

; then equip item

User avatar
Jade
 
Posts: 3520
Joined: Mon Jul 10, 2006 6:42 am


Return to Fallout 3