Random Numbers in an Attack Script

After scouring various C++ sites and hours of digging in the HWiki, I am stumped. I'll admit, I'm a noob of noobs at this part, so try not to be too harsh.

I want to generate a random number between 1 - 10 for the finalize section of an attack script, and my first try wasn't so good. Everything worked except the "random" number was always the same. I was getting some great help in game, but I don't want to keep taking up his time and bugging him with my stupid noob questions so ....

What's the simplest, easiest way to code a simple random number generator into an attack script in hackscript?

Hope this helps

I think the confusion you're having is that the rand() function in C++ returns a number between 0 and RAND_MAX, which is declared to be around 32767. So to scale it to a range you would use a function like: (rand()%10)+1 to get values from 1 to 10.

The rand() function in HS, however, returns a value equal to or greater than 0 and less than 1 (at least that is what I'm led to believe). In order to scale this to a range you would need to use a little different code. If you wanted to get a number between 1 and 10 (including 1 and 10) you would use something like the following: intValue((rand()*10)+1 ). The rand() function would give you a value between 0 and 1 and then multiply it by your range in order to get a number in that range. It adds 1 so that the range is between 1 and 10 instead of between 0 and 9. The final thing it does is pass it through the function intValue() which will truncate and decimal points and return an integer. I have written a function below that you should be able to paste into your code that will allow you to input to integers and it will return and integer greater than or equal to the lower bound and less than the upper bound.

int generateRandomNumber(int lowerBound, int upperBound)
{
int range = upperBound - lowerBound;
return ( intValue( (rand()*range)+lowerBound ) );
}

If I've made some mistake someone please correct me. Hope this helps.

-----------------------------------------
Give a man a fish and he eats for a day. Teach him how to fish and you get rid of him all weekend.

Nice custom func

That's a nice lil' snippet. WIKI THAT SHIIT!

[9:13:12 PM] ltlwinters: you're still uber uber uber gay.
[9:13:18 PM] bastard: only for you

A day in the life of a hackwars moderator.