SA-MP Forums Archive
Random float - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random float (/showthread.php?tid=196334)



Random float - CaHbKo - 05.12.2010

Does anyone know a function to generate a random float? I need it to work just like random() but for floats.

I\'ve made one myself, but using format() for stuff like this is not very good. This works, by the way:
Code:
stock randomfloat(Float:max)
{
	new bob[32], floats[2][16];
	format(bob, 32, \"%0.1f\", max);
	split(bob, floats, \'.\');
	format(bob, 32, \"%d.%d\",random(strval(floats[0])), random(strval(floats[1])));
	return _:floatstr(bob);
}



Re: Random float - SkizzoTrick - 05.12.2010

like?
new rand = random(200);
?


Re: Random float - CaHbKo - 05.12.2010

Quote:
Originally Posted by SkizzoTrick
View Post
like?
new rand = random(200);
?
More like:
Code:
new Float:rand = randomfloat(200.0);



Re: Random float - CaHbKo - 06.12.2010

Bump bump.


Re: Random float - cessil - 06.12.2010

say you wanted a float from 0.0000-2.0000 you could do
pawn Code:
new Float:myRandomFloat = float(random(20000)/10000);
untested, but you get the idea