ID:195060
 
//Title: Random Floating Point 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!


proc/randomf(num, skew = 50)
ASSERT(skew <= 100 && skew >= 0)
var/min = num*((100-skew)/100)
var/max = num*((100+skew)/100)
return( rand() * (max-min) + min )



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

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

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

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

//*/