AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Quick Question: 50% Chance of something (https://forums.alliedmods.net/showthread.php?t=130076)

Drak 06-20-2010 01:32

Quick Question: 50% Chance of something
 
Easy question. Would this be the correct away of getting a "50% chance" of something happening?

Code:
if(!(random(10) < 5)) // stop

RedRobster 06-20-2010 03:34

Re: Quick Question: 50% Chance of something
 
I would do
PHP Code:

if( random(2) ) //Random takes the Max-1, then finds a random no. between 0 and that number
{
      
//Hi! <-This would happen if it returned 1
} else { 
      
//Bye! <- This would happen if it returned 0


:)

xPaw 06-20-2010 03:40

Re: Quick Question: 50% Chance of something
 
Well 50% chance would be random( 100 )
because 5 of 10 would happen more than 50 of 100 and ofcourse 1 of 2, thats what i think

RedRobster 06-20-2010 03:59

Re: Quick Question: 50% Chance of something
 
Well...technically, it should be a 50/50 chance as this. However, as xPaw pointed out, the more times you run the same test, the higher the likelihood of the outcome being closer to what was expected.

mottzi 06-20-2010 08:47

Re: Quick Question: 50% Chance of something
 
set a booleen, then do a random which can be 1 or 0.

thats 50% chance

fysiks 06-20-2010 13:27

Re: Quick Question: 50% Chance of something
 
Quote:

Originally Posted by Drak (Post 1213948)
Easy question. Would this be the correct away of getting a "50% chance" of something happening?

Code:
if(!(random(10) < 5)) // stop

Yes.

But, I use this for clarity:

PHP Code:

#define chance(%1) ( %1 > random(100) ) // %1 = probability

if(chance(50))
{
    
// do stuff



Drak 06-20-2010 18:21

Re: Quick Question: 50% Chance of something
 
Sweet. Thanks guy's.


All times are GMT -4. The time now is 14:43.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.