Random float
#1

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);
}
Reply
#2

like?
new rand = random(200);
?
Reply
#3

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

Bump bump.
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)