Author Topic: Random Numbers  (Read 1951 times)

Windlord

  • Guest
Random Numbers
« on: January 11, 2011, 03: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
« Last Edit: May 30, 2011, 11:31:15 pm by Windlord »

Cutton

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Random Numbers
« Reply #1 on: April 23, 2011, 05: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

Windlord

  • Guest
Re: Random Numbers
« Reply #2 on: April 24, 2011, 01:01:40 pm »
Thanks Cutton, your function is obviously the more 'random' solution  ;)

 

© Liberty Unleashed Team.