ID:195145
 
//Title: Random Numbers with Tendency
//Credit to: Jtgibson
//Contributed by: Jtgibson


//This random number snippet generates a number
// between (100-skew)% and (100+skew)% of the argument
// provided; in other words, the calculations will tend
// towards the given number, but they will be random
// within the general area.
//By default, the skew is 50, giving a roll between
// 50% and 150%.

//The skew parameter determines the extent of the
// variation. This is a percentage from 0-100 - any
// other values will be rejected and the proc will crash!

//Note: This only produces integer results.


proc/random(num, skew = 50)
ASSERT(skew <= 100 && skew >= 0)
return( \
rand( \
round( num*((100-skew)/100) ), /* low bound */
round( num*((100+skew)/100), 1) /* high bound */ \
)\
)


///*
//Testing code/sample implementation:

mob/verb/test_random_1()
usr << random(100) //random between 50 and 150

mob/verb/test_random_2()
usr << random(100, 10) //random between 90 and 110

mob/verb/test_random_3()
usr << random(50, 10) //random between 45 and 55

//*/