//Title: Probability Function
//Credit to: Jtgibson
//Contributed by: Jtgibson
//Original idea from Angband/ZAngband
//This simple macro generates a probability roll based on a
// ratio of "one in [chance]". For example, a 1 in a million
// chance is described as ONE_IN_(1000000).
//This is very useful in if() statements. ONE_IN_(X) returns
// 1 if the roll is successful and 0 otherwise. Thus,
// if(ONE_IN_(1000)) will return true (on average) 0.1% of the
// time.
#define ONE_IN_(X) (!rand(0,(X)-1))
///*
//Testing code/sample implementation:
mob/verb/test_one_in()
usr << "Rolling a one in three chance:"
if(ONE_IN_(3))
usr << "SUCCESS!"
else
usr << "Failure."
//*/
ID:195147
Nov 21 2006, 7:01 am (Edited on Feb 4 2008, 1:51 pm)
|
|