bma Posted November 3, 2014 Report Share Posted November 3, 2014 Hello I have a very simple question. If i want to create a random number between 0 and 1000 but it has to be float, how do it do it? I tried:float NA = rand()%1000.f; But it gave me an error. Quote Link to comment Share on other sites More sharing options...
Hoppah Posted November 3, 2014 Report Share Posted November 3, 2014 Aint simple Tryfloat NA = ((float)Math::rand()/(float)Math::RANDMAX)*1000;Not sure if it works, scripts always act weird. Try adding the following below that to see what value it spits out (in the logfile):System::Log("NA: %d", (int)NA);Good luck! Quote Link to comment Share on other sites More sharing options...
Chris07 Posted November 4, 2014 Report Share Posted November 4, 2014 Do you need to generate a random float? (ie. 123.4552, or 12422.7844)? Or do you just need a random integer in a float data type? If you just need an integer in a float type, a simple Type-Cast as hoppah demonstrated above will work sufficiently. Since you're going from less precision (integer) to more precision (floating point number) the game shouldn't give you any grief. YOu start running into problems when you try and explicitly cast precise number formats into less percise formats such as float to integer. Even then it would usually only throw a Warning which I doubt the game even does. Quote Link to comment Share on other sites More sharing options...