Legacy GM a little question about "randomize();"

Hey,

as I'm messing with randomized AI coding, I'm in need of an information about "randomize();"
Here, I have a code bracket that does things with choose(n1, n2) and random_range(x1, x2);
Code:
if (state == "wander")
   {
   //randomize();  <---
   if (alarm[1] == -1)
     {
      alarm_set(1, room_speed*random_range(2,5));
      moveDir = choose("right", "left");
     }
    if sprite_index =! (sMoveRight or sMoveLeft)
     {
      sprite_index = choose(sMoveRight, sMoveLeft);
     }
   }
So, if I want to have the choose and random_range functions to get a random value every execution of this function, do I only need to have randomize(); in the first created object's Game Start Event or should I have it in the code bracket as its commented above?
 
S

Silver_Mantis

Guest
You only need randomize(); once, upon the start up of your game.
I placed it in my obj_Player_Stats, which was the first object to be active in the game.
 
A

altan0

Guest
randomize(); changes the random seed number for the game.

If you want to change for every decision (no pattern in behavior) then you can randomize the seed number on every decision.
 
randomize(); changes the random seed number for the game.

If you want to change for every decision (no pattern in behavior) then you can randomize the seed number on every decision. When the function is called in the create event, the random seed number will remain the same for that instance but will change when the game is restarted.
So randomize(); CAN be instance based? I'm trying to achieve different results in the copies of the same object.
 
A

altan0

Guest
So randomize(); CAN be instance based? I'm trying to achieve different results in the copies of the same object.
Its a function that you can call anywhere in a script. AFAIK there is no specific event or script it can only to be used.

Each time it is called, it will randomize the seed number.

EDIT: Apparently the seed remains the same for every game step regardless of how many calls you make!
 
Last edited by a moderator:
A

altan0

Guest
does it reduce the fps or cause latency in any way?
I just tested the randomize(); output and it doesn't lag even with 50 over objects calling it.

What is surprising is that, I just found out that the seed number DOES NOT randomize for each call so calling multiple times within the same game step doesn't effect the seed number. So it only randomizes the seed number in the next step and calling it once per game step is more than enough.

randomize_not_random_seed.png
 
Last edited by a moderator:

CMAllen

Member
does it reduce the fps or cause latency in any way?
There's some math involved in its use, so, yes, but no more than generating a random value from a seed. Still, you don't need to be regenerating seed values every step. It's not individualized to the instance; its effect is game-wide. If you're really concerned about proper randomness, you can use the first return of the seed to set an alarm for some object which will then generate a new seed when that alarm gets called (and then repeat the alarm/seed process). Even still, that seems a little excessive. Even creating a dozen random numbers per step isn't going to result in a discernible pattern for perhaps as long as hours.
 
Top