Help with calculation - advice needed

Post » Mon May 05, 2014 5:09 pm

Morning all! I'm in need of some help figuring out the best way to manage my problem.

I have 3 object in a formlist. I want to find a way to choose one object with the following chance:

Object 1 - 75% chance
Object 2 - 20% chance
Object 3 - 5% chance

Currently I'm thinking the best way may be to run 3 random integer generations like so:

iValue = http://forums.bethsoft.com/topic/1500180-help-with-calculation-advice-needed/Utility.RandomInt(1, 4)	if iValue <= 3; 75% chance		;Object 1 is chosen	endifiValue = Utility.RandomInt(1, 5)	if iValue <= 1; 20% chance		;Object 2 is chosen	endifiValue = Utility.RandomInt(1, 20)	if iValue <= 1; 5% chance		;Object 3 is chosen	endif


Currently there is no failsafe in place so all 3 could be false. What would be the best way for me to do this? One idea I had is run a single dice roll of 1 to 100, and simply use the following:

Int iValue = http://forums.bethsoft.com/topic/1500180-help-with-calculation-advice-needed/Utility.RandomInt(1, 100)	if iValue <= 75; 75% chance		;Object 1 is chosen	elseif iValue <= 95; 20% chance		;Object 2 is chosen	elseif iValue <= 100; 5% chance		;Object 3 is chosen	endif


The reason I haven't settled for the second option yet is I'm not satisfied that this method will be fair and random.

I appreciate any thoughts from you folk :smile:
User avatar
Emma Parkinson
 
Posts: 3401
Joined: Wed Jul 26, 2006 5:53 pm

Return to V - Skyrim