Raised This Month: $51 Target: $400
 12% 

Quick Question: 50% Chance of something


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 06-20-2010 , 01:32   Quick Question: 50% Chance of something
Reply With Quote #1

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

Code:
if(!(random(10) < 5)) // stop
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
RedRobster
Veteran Member
Join Date: Apr 2010
Location: Your Closet
Old 06-20-2010 , 03:34   Re: Quick Question: 50% Chance of something
Reply With Quote #2

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


Last edited by RedRobster; 06-20-2010 at 03:37.
RedRobster is offline
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 06-20-2010 , 03:40   Re: Quick Question: 50% Chance of something
Reply With Quote #3

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
__________________
xPaw is offline
RedRobster
Veteran Member
Join Date: Apr 2010
Location: Your Closet
Old 06-20-2010 , 03:59   Re: Quick Question: 50% Chance of something
Reply With Quote #4

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.
RedRobster is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 06-20-2010 , 08:47   Re: Quick Question: 50% Chance of something
Reply With Quote #5

set a booleen, then do a random which can be 1 or 0.

thats 50% chance
mottzi is offline
Send a message via MSN to mottzi
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-20-2010 , 13:27   Re: Quick Question: 50% Chance of something
Reply With Quote #6

Quote:
Originally Posted by Drak View Post
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

__________________
fysiks is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 06-20-2010 , 18:21   Re: Quick Question: 50% Chance of something
Reply With Quote #7

Sweet. Thanks guy's.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:01.


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