Bots break math.random

You have no idea how much of a headache and how long it took me to find this out.

I was coding and testing a gamemode, I was testing it by hosting a lan listen server with bots on.
I had a system that was suppose to give me random powerups but…
It kept giving me the same powerup everytime even though I was using math.random.

After racking my brains out trying to find the source of the problem I did this:



function GM:KeyPress( pl, key )
    if key == IN_ATTACK2 then
         print( math.random(1,6) )
    end
end


Restart the server add a bot and right click away. I got this:
3333333333333333333333333333333323333333333333333323333333333333

Seems to be only 3 but It spurts out a 2 every now and then.
So I was right clicking at different parts of the round etc etc same result.
BUT THEN I kicked the bot off the server and IMMEDIATLY:
515625265254466

Add a bot:
333333333333333333333333333333
Kick bot:
65113215611466433

It’s not just the KeyPress function too, same on Think, any custom function so the bots are somehow overriding math.random()

Gah -rests head-

Hm, it’s not happening to me.



CapsAdmin: !lua local tbl = {} for i=1, 50 do table.insert(tbl,math.random(6)) end print(table.ToString(tbl))
{3,4,5,5,4,2,2,6,2,6,1,6,6,3,5,2,4,6,1,1,5,4,3,4,2,6,6,5,1,2,1,5,6,3,3,2,6,5,4,2,4,1,2,4,1,4,4,2,2,2,}
CapsAdmin: !rcon bot
Player Bot01 has joined the game
CapsAdmin: !lua local tbl = {} for i=1, 50 do table.insert(tbl,math.random(6)) end print(table.ToString(tbl))
{4,3,2,2,2,5,3,5,5,2,4,1,2,4,2,3,2,2,2,3,4,6,5,1,5,3,4,1,2,1,1,2,2,1,3,5,1,6,1,2,2,4,1,5,2,4,4,5,4,2,}


Maybe you could try messing with those seed functions. But there must be something in your gamemode that does it.

Maybe it’s a listen server thing.

EDIT:
Oh wow. it’s bot_zombie 1.

If bot_zombie is 0 then math.random works fine, as sooon as I change bot_zombie to 1 it breaks.

I’ll try on a listen server too. Hold on.

[editline]12:09PM[/editline]

Same results.

even with bot_zombie 1?

edit:
This is really strange.

If I try math.random in console with bot_zombie 1 on, it works.
If I have math.random run from the gamemode, such as KeyPress, with bot_zombie 1, on it doesn’t work.
If bot_zombie is 0, it works both in console and from gamemode functions.