Game Development Community

Using rand() in Torque Script

by Daniel Ly · in Technical Issues · 08/12/2005 (2:17 pm) · 3 replies

Hey,

I know in the Torque C++ sdk there's a MRandomGenerator Class, but I was wondering if there's a way to generate random numbers using TorqueScript?

Thanks,
Daniel

#1
08/12/2005 (2:21 pm)
Yes, several ways

// get a number between 0 and 1
%rand = getRandom();

// get a number between 0 and X
%rand = getRandom(X);

// get a number between X and Y
%rand = getRandom(X, Y);
#2
08/12/2005 (2:23 pm)
These are all inclusive, also.
#3
08/12/2005 (2:30 pm)
Also forgot to mention.
getRandom without any arguments generates floats between 0 and 1, inclusive.
Whereas getRandom with arguments generates whole numbers.