Liberty Unleashed

Scripting => Script Snippets => Topic started by: Windlord on January 11, 2011, 02:12:52 pm

Title: Random Numbers
Post by: Windlord on January 11, 2011, 02:12:52 pm
Code: (squirrel) [Select]
// This function generates random integers depending on the arguments.
// If you supply one argument, it'll return a number between 1 and the provided number
// If you supply two arguments where the 2nd one is larger, it'll provide a number between the two
function RandNum ( start, end = 0 )
{
if ( !end ) { end = start; start = 1; }
return start + ( rand() % ( end - start + 1 ) );
}

Edit: Increased randomness of function thanks to Cutton
Title: Re: Random Numbers
Post by: Cutton on April 23, 2011, 04:23:31 pm
Just noticed this here, I wrote a slightly improved function for random number and posted it here: http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=301.0
Title: Re: Random Numbers
Post by: Windlord on April 24, 2011, 12:01:40 pm
Thanks Cutton, your function is obviously the more 'random' solution  ;)