Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 20:05
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, AndrewAMD), 1,375 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 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