1. ## Re: Gettng Random number

Here is a function to do it:

</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;"># Function: getRandom
# Purpose: Generates integer random numbers between a range
# Parameters: in Minimum (integer), in Maximum(integer)
# Return Values: EmptyString indicates error, else random number is returned

function getRandom(in iMin, in iMax)
{
auto iRange;
if (iMin &lt; 0 &#0124;&#0124; iMin &gt; iMax &#0124;&#0124; (iMin + iMax)==0)
return;
if (int(iMin) != iMin &#0124;&#0124; int(iMax) != iMax)
return;
iRange=(iMax-iMin) + 1;
return(int(rand()*iRange) + iMin);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">

2. ## Re: Gettng Random number

Hi,

Thanks for the solution

Lee

3. ## Gettng Random number

HI,

I have a question.
Please tell how to get a random number between two digits.
I tried writing compiled module for that like
get_max(max,min)

thanks.
Lee

4. ## Re: Gettng Random number

Here is another one that may be of use to you guys... This is written as a C module but you could very easily change it to be TSL.

int GetRandom(int min, int max)
{
// Generate a random number between min and max (This function can take a while to return the result simply due to the
// way in which the number is generated.
// This function simply generates a random number and then checks to see if it is between the min and max values, if not
// another random number is generated. This proccess is repeated until the generated number is between the min and max.
int rndnum;

srand( clock() );
do
{
rndnum = rand();
}
while (rndnum > max &#0124;&#0124; rndnum < min);

return rndnum;
}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
BetaSoft Inc.
All times are GMT -8. The time now is 04:16 PM.