Get a random between 2 numbers
Posted: Mon Jul 05, 2010 4:43 am
Heres how to get a random between 2 different numbers. The result is stored in a variable called "rv" so if you want to be able to use this random function correctly, use that variable.
First, put this in global code
Now when ever you wanna make a random between 2 numbers, simply put this:
This will have rv store anything from 9 to 32, and everything in between. IF you want to use this without the decimals, than replace "float rv;" with "int rv"
Enjoy
First, put this in global code
- Code: Select all
float rv;
void random(float first, float second)
{
rv = rand(first+second);
if (rv<first)
{
rv = first;
}
if (rv>second)
{
rv = second;
}
}
Now when ever you wanna make a random between 2 numbers, simply put this:
- Code: Select all
random(9, 32);
This will have rv store anything from 9 to 32, and everything in between. IF you want to use this without the decimals, than replace "float rv;" with "int rv"
Enjoy