Generating random integers (vs. floats)
by Zachary Seldess · in Torque Game Engine · 07/06/2007 (4:17 pm) · 3 replies
Hi everyone,
Is there a simple way to the getRandom() function to generate integers?
This is what I did to generate a true/false scenario, theres' got to be a better way...
Is there a simple way to the getRandom() function to generate integers?
This is what I did to generate a true/false scenario, theres' got to be a better way...
if(%b <= 0.9 && %b >= 0.1){
%bdirection = mFloor(getRandom(1.99));
if(%bdirection == 0.0)
%b += 0.01;
else
%b -= 0.01;
}About the author
#2
07/06/2007 (10:44 pm)
I thought when you specified getRandom(0, 1); you will get a range of FLOATS between 0.0 and 1.0, not just the two possibilities that I'm going for (0 and 1). Does the type of the parameter dictate the behavior of the function - in other words, if I use "0 and 1" instead of "0. and 1.", will I get an int output?
#3
08/27/2012 (4:28 pm)
It gives you a float if you *don't* specify numbers. As soon as a number is added, it becomes an integer.
Torque Owner Caleb
Default Studio Name
So to get a fifty-fifty chance: %num = getRandom(0, 1);