[Question] Random Float?
#1

I tried this code (just an example):

pawn Code:
new
    Float:randx = 5.0,
    Float:res = random(randx);
And I'm getting a warning of "Tag Mismatch".
Any ideas how to make a random float?
Reply
#2

Cause the function random only supports integers, not floats, and your using a float as a value.
So tag mismatch.

Now you can try to remove the tag check on the float using _: aka Tag Override.
It will remove the warning, however I am not a fan of floats, but testing this out comes out to very small random floats.

(For example your using 5.0 as max, but some of my results were 0.0000345, 0.000018 etc..., that's small)

Heres my code:

pawn Code:
for (new i = 0; i < 1000; i++) {
        new Float:randx = 5.0, res = random(_:randx);
        printf("%f", res);
    }
Now you might be wondering why I'm not storing res in a Float, but outputting it as a float, is cause it just doesn't work. You get massive values such as 894232.123455 which is obviously Much larger then 5.0...
Only this way seems to make them somewhat of random floats within the size.
(I could be completely wrong but meh, floats aren't my thing)
Reply
#3

Okay, its working, but a few problems..
1. Very small results (as you said before: 0.0000something)
2. It prints lots of numbers (when I type /test) - I guess thats because of the loop
Well, I found my own way to random that code:

pawn Code:
new Float:randx1 = random(4);
new Float:randy1 = random(8);
new Float:randx = floatsqroot(floatdiv(randx1, 1.23));
new Float:randy = floatsqroot(floatdiv(randy1, 1.63));
Thanks anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)