Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 482 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[SUB] Fixed percent of bool true answers on random samples #443388
07/15/14 06:46
07/15/14 06:46
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
I wrote a little module to manage the flux by a percent of success. It has no patterns or weird accumulations on a very simple process.

Code:
typedef struct 
{
	var percent;
	var balance;
} PERCBOOL;

PERCBOOL *pboolCreate ( var percent )
{
	PERCBOOL *pbool = sys_malloc ( sizeof(PERCBOOL) );
	pbool->percent = clamp ( percent, 0, 100 );
	pbool->balance = pbool->percent;
	return pbool;
}

void pboolRemove ( PERCBOOL *pbool )
{
	sys_free ( pbool );
}

BOOL pboolSample ( PERCBOOL *pbool )
{
	var percent = random ( 100 );
	if ( pbool->balance > percent )
	{
		pbool->balance -= 100 - pbool->percent;
		return TRUE;
	}
	else
	{
		pbool->balance += pbool->percent;
		return FALSE;
	}
}

void pboolModify ( PERCBOOL *pbool, var percent )
{
	pbool->percent = clamp ( percent, 0, 100 );
	pbool->balance = pbool->percent;
}



Code:
action actPlayer ()
{
   PERCBOOL pbCriticalHit;
   pboolModify ( &pbCriticalHit, 13.5 );
   ...
   if ( pboolSample ( &pbCriticalHit ) )
   ...
}



Salud!

Re: [SUB] Fixed percent of bool true answers on random samples [Re: txesmi] #443396
07/15/14 16:16
07/15/14 16:16
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Some screens.
'random(100) < percent' draws the green squares. The top number is the overall sample proportion.



Filtered with the module:



33%:



As you can see, if you take a subgroup of contiguos samples of any size in the fixed sets the ratio tends to the desired percent while mantains a random behavior. Which does not occur with the stark comparison.

Salud!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1